How unit 2 is examined
Algorithms and flowcharts, programming languages and paradigms, OOP concepts, and C++ basics; algorithms, OOP and C++ (arrays, loops, operators, data types, programs) carry the marks.
Introduction to Algorithms, Complexities and Flowchart
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">High weight</span>
Definition. <mark>An algorithm is a finite, ordered set of unambiguous steps that takes input and produces the required output for solving a problem.</mark> A flowchart is its pictorial form, drawn with standard symbols joined by arrows.
Key points.
- An algorithm has finiteness (it ends), definiteness (each step is clear), input, output and effectiveness (each step is doable).
- It is needed because it fixes the logic first, so the program is written once, without trial and error.
- Benefit one: it is language independent, so the same steps can be coded in C++, Java or Python.
- Benefit two: step-by-step logic is easy to test, debug and optimise before coding.
- Benefit three: a large problem splits into modules, which makes it scalable and easy to modify.
- A flowchart shows the flow visually, so logic errors and missing branches are seen at once; together they reduce errors and save development time.
- Time complexity is the number of steps as a function of input size $n$; space complexity is the memory needed, and both are measured by asymptotic notation, ignoring machine speed.
- Best, average and worst cases are the fewest, typical and most steps; worst case is usually quoted.
| Notation | Meaning |
|---|---|
| Big-O, $O(f(n))$ | upper bound (worst case) |
| Big-Omega, $\Omega(f(n))$ | lower bound (best case) |
| Big-Theta, $\Theta(f(n))$ | tight bound (both) |
Classes in increasing cost: $O(1)$ constant, $O(\log n)$, $O(n)$ linear, $O(n^2)$ quadratic.
Diagram. Symbols: oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision, arrow = flow.
<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u2-01" viewBox="0 0 286.4 398.2" width="286.4" height="398.2" role="img" aria-label="Maximum of two numbers. S = Start, I = Input A, B, D = Is A > B?, Y = Print A is maximum, N = Print B is maximum, E = Stop"><style>#dsfig-u2-01 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u2-01 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u2-01 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u2-01 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u2-01 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u2-01 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u2-01 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u2-01 .t{fill:#16181D;font-weight:500}#dsfig-u2-01 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u2-01 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u2-01 .dot{fill:#16181D}#dsfig-u2-01 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u2-01 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u2-01 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u2-01 .ah{fill:#454C5A}#dsfig-u2-01 .ah.hi{fill:#2340B8}#dsfig-u2-01 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u2-01 .wl .t{font-size:12px;font-weight:700}#dsfig-u2-01 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u2-01 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u2-01 .e{stroke:#B1B7C3}html.dark #dsfig-u2-01 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u2-01 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u2-01 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u2-01 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u2-01 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u2-01 .t{fill:#E6E8ED}html.dark #dsfig-u2-01 .t.inv{fill:#0F1115}html.dark #dsfig-u2-01 .kd{stroke:#E6E8ED}html.dark #dsfig-u2-01 .dot{fill:#E6E8ED}html.dark #dsfig-u2-01 .ann{fill:#8FA3FF}html.dark #dsfig-u2-01 .lbl{fill:#858D9C}html.dark #dsfig-u2-01 .ptr{fill:#8FA3FF}html.dark #dsfig-u2-01 .ah{fill:#B1B7C3}html.dark #dsfig-u2-01 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u2-01 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u2-01 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u2-01 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah4" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh4" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><path class="e" d="M143.2,59 L143.2,96.4" marker-end="url(#ah4)"/><path class="e" d="M143.2,136.4 L143.2,173.8" marker-end="url(#ah4)"/><path class="e" d="M128.6,207 L56.1,267.4" marker-end="url(#ah4)"/><path class="e" d="M157.8,207 L230.3,267.4" marker-end="url(#ah4)"/><path class="e" d="M55.2,292.2 L126.4,345.6" marker-end="url(#ah4)"/><path class="e" d="M231.2,292.2 L160,345.6" marker-end="url(#ah4)"/><g class="wl"><rect x="74.8" y="228.8" width="33.6" height="18" rx="9"/><text class="t" x="91.6" y="237.8" dy=".35em" text-anchor="middle">Yes</text></g><g class="wl"><rect x="181.6" y="228.8" width="26.4" height="18" rx="9"/><text class="t" x="194.8" y="237.8" dy=".35em" text-anchor="middle">No</text></g><circle class="n" cx="143.2" cy="40" r="18"/><text class="t" x="143.2" y="40" dy=".35em" text-anchor="middle">S</text><circle class="n" cx="143.2" cy="117.4" r="18"/><text class="t" x="143.2" y="117.4" dy=".35em" text-anchor="middle">I</text><circle class="n" cx="143.2" cy="194.8" r="18"/><text class="t" x="143.2" y="194.8" dy=".35em" text-anchor="middle">D</text><circle class="n" cx="40" cy="280.8" r="18"/><text class="t" x="40" y="280.8" dy=".35em" text-anchor="middle">Y</text><circle class="n" cx="246.4" cy="280.8" r="18"/><text class="t" x="246.4" y="280.8" dy=".35em" text-anchor="middle">N</text><circle class="n" cx="143.2" cy="358.2" r="18"/><text class="t" x="143.2" y="358.2" dy=".35em" text-anchor="middle">E</text></svg><figcaption style="font-size:.82em;opacity:.72;margin-top:.45rem">Maximum of two numbers. S = Start, I = Input A, B, D = Is A > B?, Y = Print A is maximum, N = Print B is maximum, E = Stop</figcaption></figure>
Example. Largest of three numbers:
Step 1: Start
Step 2: Read A, B, C
Step 3: If A > B and A > C, print A
Step 4: Else if B > C, print B
Step 5: Else print C
Step 6: Stop
Limitations of flowcharts. They become cluttered and hard to follow for big programs; modifying them means redrawing; they have no standard for recursion or concurrency; and they show logic but not data or detail, so readability falls as the algorithm grows.
Answer frame. Open with the definition and properties; for "why needed" list points 2-6, then close with fewer errors and less time; for complexity define time and space, cases, the notation table, examples; for flowchart draw the figure with symbols first, then the algorithm steps; for limitations open with what a flowchart is, then the four limits.
Asked: [7 marks] (Nov 2022) Why Algorithm writing and drawing flow chart is necessary before writing a computer program? Asked: [7 marks] (Dec 2023) Discuss the various sorts of algorithmic complexities, such as time and space complexity, as well as how they are quantified. Asked: [7 marks] (Jun 2023) Define algorithms. What is the need of algorithms? Describe three benefits of algorithms. Asked: [7 marks] (Dec 2024) What are limitations do flowcharts have in representing complex algorithms or processes? Asked: [7 marks] (Dec 2024) Explain how to create a flowchart for a simple algorithm, such as finding the maximum of two numbers. Asked: [7 marks] (Jun 2025) What is an algorithm? Write an algorithm to find largest value from the given three numbers.
Introduction to Programming, Categories of Programming Languages, Program Design, Programming Paradigms
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Medium weight</span>
Definition. <mark>A programming language is a formal set of rules and symbols used to write instructions that a computer can execute.</mark> Categories are machine, assembly (low-level) and high-level languages.
Key points.
- Machine language is binary, runs directly, and is hardware specific.
- Assembly language uses mnemonics such as ADD and MOV, and needs an assembler to convert it to machine code.
- High-level languages use English-like statements and are translated by a compiler or interpreter.
- Program design means understanding the problem, writing the algorithm and flowchart, coding, testing and documenting.
- A paradigm is a style of programming: procedural (C) organises code as functions, object-oriented (C++, Java) as objects, functional (Haskell, Lisp) as pure functions.
| Point | Assembly language | High-level language |
|---|---|---|
| Readability | mnemonics, harder | English-like, easy |
| Portability | machine dependent | portable |
| Speed | faster, close to hardware | slower after translation |
| Translator | assembler | compiler / interpreter |
| Memory control | direct | mostly automatic |
| Use | drivers, embedded | applications, data science |
| Examples | 8085 assembly | C++, Python |
| Paradigm | Focus | State |
| --- | --- | --- |
| Procedural | functions in sequence | shared global data, mutable |
| Object-oriented | objects with data and methods | hidden inside objects, mutable |
| Functional | pure functions | immutable, no side effects |
Answer frame. Open with the definition and categories; draw the table row by row; give an example language per column; close with when each is used. For paradigms, define each in one line, then the table, then benefits and drawbacks.
Asked: [7 marks] (Nov 2022, Dec 2023) What is a Programming language? Differentiate Assembly level language and High Level language. Compare low-level and high-level languages by characteristics and use cases. Asked: [7 marks] (Dec 2023) Contrast programming paradigms including procedural programming, object-oriented programming and functional programming. Discuss their benefits and drawbacks.
Characteristics or Concepts of OOP, Procedure Oriented Programming VS object oriented Programming
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">High weight</span>
Definition. <mark>Object-oriented programming (OOP) organises a program as objects that bind data and the functions working on it.</mark> Procedure-oriented programming (POP) organises it as a sequence of functions acting on shared data.
Key points (concepts of OOP).
- A class is a blueprint that defines data and functions; an object is an instance of a class.
- Encapsulation binds data and member functions into one unit, the class.
- Data hiding keeps data private so only member functions can reach it.
- Abstraction shows only essential features and hides the implementation details.
- Inheritance lets a derived class acquire the properties of a base class, giving reuse.
- Polymorphism is one name with many forms: compile-time (overloading) and run-time (virtual functions).
- Dynamic binding decides at run time which function is called; message passing means objects communicate by calling each other's functions.
Encapsulation. It is important because private and protected specifiers block outside interference, giving security, modularity and easy maintenance.
POP. It follows top-down design, divides the program into functions, and most data is global and open to every function.
int add(int a, int b) { return a + b; } /* function */
int main() { int s = add(2, 3); return 0; } /* s = 5 */
Its limits are insecure global data, poor reuse, and difficulty modelling real objects.
| Point | POP | OOP |
|---|---|---|
| Focus | functions | objects |
| Approach | top-down | bottom-up |
| Data | global, unprotected | hidden inside objects |
| Reuse | little | inheritance |
| Examples | C, Pascal | C++, Java |
Answer frame. For OOP open with the definition, then develop points 1-7 in order, close with reuse and security. For POP define, list characteristics, show the C example, close with limits. For encapsulation define, explain access specifiers, then importance.
Asked: [7 marks] (Jun 2022, Jun 2024) Explain the concepts of OOP. What are the principles of Object-Oriented Programming (OOP)? Asked: [7 marks] (Jun 2023) Explain procedure-oriented programming with examples. Asked: [7 marks] (Dec 2024) What is encapsulation and why is it important in OOP?
Introduction to C++: Character Set, Tokens, Precedence, Data Types, Operators, Control Structures, Arrays, Functions
<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">High weight</span>
Definition. <mark>C++ is a general-purpose object-oriented language that extends C with classes.</mark> A program has header files (#include <iostream>), using namespace std;, then main().
Key points.
- The character set is letters, digits, special symbols and white space.
- Tokens are the smallest units of a program: keywords, identifiers, literals, operators and punctuators.
- A variable is a named memory location whose type fixes its size; the name starts with a letter or
_, has no spaces, and is not a keyword. - Primitive types are
int,char,float,double,bool; derived types (array, pointer, reference, function) are built from them; user-defined types arestruct,class,enum. - Precedence decides which operator acts first (
*before+); associativity decides the order for equal precedence (=right to left,+left to right). - I/O uses
cin >> x;andcout << x;.
| Primitive | Derived |
|---|---|
| Built into the language | Made from primitive types |
int a; char c; |
int arr[5]; int *p; |
Operators. Arithmetic (+ - * / %), relational (< > == !=), logical (&& || !), bitwise (& | ^ ~ << >>), assignment (= += -=). C++ adds scope resolution ::, new and delete, member access . and ->, pointer-to-member .* and ->*.
Loops. for and while are entry-controlled (condition first); do-while is exit-controlled, so it runs at least once.
for (int i = 0; i < 3; i++) cout << i; // 012
while (i < 3) { i++; }
do { i--; } while (i > 0);
Arrays. An array holds elements of one type in contiguous memory. A 1D array has one index; a 2D array has two, in matrix form.
int a[3] = {1, 2, 3}; // 1D
int m[2][2] = {{1, 2}, {3, 4}}; // 2D: m[1][0] = 3
Programs.
#include <iostream>
using namespace std;
int main() {
int a = 5, b = 9, t;
t = a; a = b; b = t;
cout << a << " " << b; // 9 5
}
long n = 1101; int d = 0, p = 1;
while (n > 0) { d += (n % 10) * p; p *= 2; n /= 10; }
cout << d; // 13
Answer frame. For a program, include header, declare, input, logic, output. For arrays define, draw both declarations, give a program. For data types classify, then table. For operators list the groups then the special ones. For loops define, then each loop with syntax.
Asked: [7 marks] (Jun 2022) Explain the various kinds of looping statements in C++? With examples. Asked: [7 marks] (Jun 2022) Write a program in C++ to convert the given binary number into the decimal number. Asked: [7 marks] (Nov 2022, Jun 2024) What is an Array? Explain different types of Arrays with syntax and suitable example programs. Explain the difference between one-dimensional and multi-dimensional arrays. Asked: [7 marks] (Dec 2023) Explain what "data types" are used in C++ and what the difference is between "primitive" and "derived" data types? Give an example of each one. Asked: [7 marks] (Jun 2023) Explain: i) data type ii) tokens iii) variables iv) operator Asked: [7 marks] (Jun 2025) List and explain various operators in object oriented program. Asked: [7 marks] (Jun 2025) Write a C++ program to swap two numbers.
Last-minute revision
- An algorithm is finite, definite, has input and output, and is effective.
- Flowchart symbols: oval start/stop, parallelogram I/O, rectangle process, diamond decision.
- $O$ is worst case, $\Omega$ best case, $\Theta$ tight bound.
- Assembly needs an assembler; high-level needs a compiler or interpreter.
- Paradigms: procedural (C), object-oriented (C++, Java), functional (Haskell).
- OOP concepts: class, object, encapsulation, abstraction, inheritance, polymorphism.
- Encapsulation binds data and functions in a class.
- Tokens: keywords, identifiers, literals, operators, punctuators.
forandwhileare entry-controlled;do-whileis exit-controlled.- Special C++ operators:
::,new,delete,.,->,.*,->*. - Binary 1101 = 13.
Memory hooks
- FDIOE: Finite, Definite, Input, Output, Effective.
- CEAIP: Class, Encapsulation, Abstraction, Inheritance, Polymorphism.
- Oval starts, diamond decides, parallelogram talks (I/O).
- Do-while does first, asks later.
Coverage checklist
- Introduction to Algorithms, Complexities and Flowchart: Nov 2022, Dec 2023, Jun 2023, Dec 2024 (two), Jun 2025.
- Introduction to Programming, Categories of Programming Languages, Program Design, Programming Paradigms: languages Nov 2022 and Dec 2023; paradigms Dec 2023.
- Characteristics or Concepts of OOP, Procedure Oriented Programming VS object oriented Programming: OOP concepts, POP, encapsulation.
- Introduction to C++: Character Set, Tokens, Precedence and Associativity, Program Structure, Data Types, Variables, Operators, Expressions, Statements and control structures, I/O operations, Array, Functions: loops, binary to decimal, arrays, data types, tokens, operators, swap.