Computers are FAST, but they are not SMART — they can't think for themselves! 🤖 A computer only does EXACTLY what it is told, step by step. So before you write even one line of Python, you must first figure out HOW to solve the problem. This chapter answers the BIG questions: What are the steps to solve a problem using a computer? What is an algorithm? How do we draw a flowchart and write pseudocode? How do we check that our solution is correct — and which solution is better? Let's learn to think like a programmer! 🧠💡
Focus especially on Steps of Problem Solving, Characteristics of a Good Algorithm, Flowchart Symbols, and writing algorithms / flowcharts for simple problems — these come as 2, 3 and 4-mark questions every year. Practise drawing each flowchart on paper!
7.1 🏁 Introduction
Problem solving is the process of identifying a problem, developing a step-by-step solution for it, and turning that solution into a working computer program.
Think about something you do every day — making a cup of tea ☕. Without even noticing, you follow a fixed sequence of steps:
1. Boil water
2. Add tea leaves
3. Add milk and sugar
4. Boil for 2 minutes
5. Strain into a cup
6. Serve
If you skip a step or do them in the wrong order (strain before boiling?! 😱), the tea is ruined. A computer is exactly the same — it needs precise, ordered steps to reach the right answer.
graph LR
PROB["❓ Problem\n(What do we need?)"]
THINK["🧠 Solution Steps\n(Algorithm)"]
CODE["💻 Program\n(Python code)"]
ANS["✅ Answer\n(Correct output)"]
PROB --> THINK --> CODE --> ANS
style THINK fill:#FF9800,color:#fff
style CODE fill:#2196F3,color:#fff
style ANS fill:#4CAF50,color:#fff
Think of it this way: A program is like a building 🏢, and the algorithm is its blueprint. No engineer starts laying bricks without first drawing a plan. No programmer should start typing code without first planning the steps!
7.2 🪜 Steps for Problem Solving
Solving a problem on a computer involves four main steps:
graph TD
S1["1️⃣ Analysing the Problem\nUnderstand WHAT is needed:\ninputs, outputs, conditions"]
S2["2️⃣ Developing an Algorithm\nWrite the step-by-step\nsolution in simple language"]
S3["3️⃣ Coding\nConvert the algorithm into\na programming language"]
S4["4️⃣ Testing and Debugging\nCheck with different inputs;\nfind and fix errors"]
S1 --> S2 --> S3 --> S4
S4 -.->|"errors found?\ngo back and fix"| S2
style S1 fill:#9C27B0,color:#fff
style S2 fill:#FF9800,color:#fff
style S3 fill:#2196F3,color:#fff
style S4 fill:#4CAF50,color:#fff
1. Analysing the Problem
Read the problem carefully; identify the INPUTS, the required OUTPUT, and any conditions or formulas
Input → ? → Output2. Developing an Algorithm
Write a finite set of clear steps that solves the problem; try more than one approach and pick the best
Plan before code3. Coding
Translate the algorithm into a high-level language like Python; this is called the source code
Algorithm → Program4. Testing and Debugging
Run the program with many different inputs (including unusual ones) to find and remove errors
Testfixre-testExample — Analysing a problem: "Find the area of a rectangle."
| Question | Answer |
|---|---|
| What are the inputs? | Length (L) and Breadth (B) |
| What is the output? | Area of the rectangle |
| What is the processing / formula? | Area = L × B |
| Any conditions? | L and B must be positive numbers |
Analyse → Develop algorithm → Code → Test & debug Remember it as: "A Dog Can Talk!" 🐕💬
"List the steps involved in problem solving." — 2-mark question! Answer: The steps are: (1) Analysing the problem — identify inputs, outputs and processing; (2) Developing an algorithm — write the step-by-step solution; (3) Coding — convert the algorithm into a program; (4) Testing and debugging — run the program with different inputs and remove errors.
7.3 📜 Algorithm
An algorithm is a finite sequence of clear, well-defined steps that solves a problem and produces the desired output for the given input.
The word "algorithm" comes from the name of the 9th-century Persian mathematician Abu Ja'far Muhammad ibn Musa al-Khwarizmi. 📚
Example — Algorithm to find the sum of two numbers:
Step 1: Start
Step 2: Input the first number, num1
Step 3: Input the second number, num2
Step 4: sum = num1 + num2
Step 5: Print sum
Step 6: Stop
7.3.1 Why Do We Need an Algorithm? 🤔
Clear Roadmap
Gives a clear plan of the solution before any coding begins
Less confusionSaves Time
Mistakes in logic are found early — on paper — not after writing code
Fewer bugsLanguage Independent
The same algorithm can be coded in Python, Java or C++
Write oncecode anywhereEasy to Share
Other people can easily understand and improve the logic
Team work7.3.2 Characteristics of a Good Algorithm ⭐
graph TD
ALGO["⭐ GOOD ALGORITHM"]
PREC["🎯 Precision\nEach step is clear\nand exact"]
UNIQ["1️⃣ Uniqueness\nResult of each step depends\nonly on input and previous steps"]
FIN["🏁 Finiteness\nStops after a finite\nnumber of steps"]
INP["📥 Input\nTakes zero or\nmore inputs"]
OUTP["📤 Output\nProduces at least\none output"]
ALGO --> PREC
ALGO --> UNIQ
ALGO --> FIN
ALGO --> INP
ALGO --> OUTP
style PREC fill:#F44336,color:#fff
style UNIQ fill:#FF9800,color:#fff
style FIN fill:#2196F3,color:#fff
style INP fill:#4CAF50,color:#fff
style OUTP fill:#9C27B0,color:#fff
| Characteristic | Meaning | Bad Example ❌ |
|---|---|---|
| Precision | Every step must be clearly and exactly stated | "Add some sugar" (how much?) |
| Uniqueness | The result of each step is uniquely defined and depends only on the input and the results of earlier steps | A step whose result changes randomly |
| Finiteness | The algorithm must stop after a finite number of steps | "Keep adding 1 to x" (never ends!) |
| Input | It receives zero or more well-defined inputs | — |
| Output | It produces at least one result (output) | An algorithm that never prints/returns anything |
Precision · Uniqueness · Finiteness · Input · Output Say it like "Puff-io!" 💨 — and imagine a puff of smoke that disappears after a FINITE time!
An algorithm is NOT a program! An algorithm is written in simple English-like steps and does not follow the strict syntax of any programming language. A program is the algorithm written in a programming language like Python.
"What is an algorithm? Write any three characteristics of a good algorithm." — 3-mark question! Answer: An algorithm is a finite sequence of well-defined steps to solve a problem. Characteristics: (1) Precision — each step is clearly defined; (2) Finiteness — it must terminate after a finite number of steps; (3) Output — it must produce at least one output.
7.4 🎨 Representation of Algorithms
An algorithm can be written in two popular ways:
graph TD
REP["🎨 REPRESENTING AN ALGORITHM"]
FC["📊 Flowchart\n(Visual — uses\nshapes and arrows)"]
PC["📝 Pseudocode\n(Text — English-like\nstatements)"]
REP --> FC
REP --> PC
style FC fill:#2196F3,color:#fff
style PC fill:#FF9800,color:#fff
7.4.1 Flowchart 📊
A flowchart is a visual (pictorial) representation of an algorithm. It uses standard symbols connected by arrows that show the flow of control.
Standard Flowchart Symbols:
| Symbol | Shape | Name | Used For |
|---|---|---|---|
| ⬭ | Oval / Rounded rectangle | Terminal | Start or Stop of the flowchart |
| ▭ | Rectangle | Process | Calculations and assignments, e.g. sum = a + b |
| ◇ | Diamond | Decision | A condition with Yes/No (True/False) branches |
| ▱ | Parallelogram | Input / Output | Reading input or printing output |
| → | Arrow | Flow Line | Shows the direction of flow |
| ○ | Small circle | Connector | Joins parts of a flowchart (e.g., across pages) |
How these shapes look in a flowchart:
graph TD
T(["Terminal: Start / Stop"])
IO[/"Input / Output: INPUT num"/]
P["Process: sum = a + b"]
D{"Decision: Is a > b?"}
T --> IO --> P --> D
style T fill:#4CAF50,color:#fff
style IO fill:#2196F3,color:#fff
style P fill:#FF9800,color:#fff
style D fill:#9C27B0,color:#fff
Example 1 — Flowchart to find the sum of two numbers:
graph TD
A(["Start"])
B[/"INPUT num1, num2"/]
C["sum = num1 + num2"]
D[/"PRINT sum"/]
E(["Stop"])
A --> B --> C --> D --> E
style A fill:#4CAF50,color:#fff
style E fill:#F44336,color:#fff
- Every flowchart has exactly one Start and at least one Stop terminal.
- Use the correct standard symbol for each kind of step.
- The flow should go from top to bottom or left to right.
- A decision box has one entry and two exits (Yes / No).
- Flow lines should not cross each other; use connectors if needed.
"Draw the flowchart symbols for: (a) Decision (b) Input/Output (c) Process (d) Terminal." — 2-mark question! Answer: Decision → Diamond ◇; Input/Output → Parallelogram ▱; Process → Rectangle ▭; Terminal → Oval ⬭. Always DRAW the shape and write its name below it.
7.4.2 Pseudocode 📝
Pseudocode (pronounced "soo-doh-code"; "pseudo" means "not real") is a way of writing an algorithm in simple, English-like statements that look similar to program code but do not follow the syntax of any programming language.
Common pseudocode keywords:
Input
Take a value from the user
INPUTREADGETOutput
Display a result
PRINTDISPLAYOUTPUTProcess
Calculate or assign
COMPUTESETINCREMENTDECREMENTDecision / Loop
Choose between paths or repeat steps
IF-ELSEWHILEFORExample — Pseudocode to find the area and perimeter of a rectangle:
INPUT length
INPUT breadth
COMPUTE area = length * breadth
COMPUTE perimeter = 2 * (length + breadth)
PRINT area
PRINT perimeter
Benefits of Pseudocode:
- Easy to write and read — no need to remember language syntax.
- Helps a programmer focus on the logic rather than the grammar of the language.
- Can easily be converted into a program in any language.
- Non-programmers (like a teacher or client) can also understand and review it.
Flowchart vs Pseudocode — The Critical Comparison:
| Feature | Flowchart | Pseudocode |
|---|---|---|
| Form | Pictorial (shapes and arrows) | Text (English-like statements) |
| Ease of understanding | Very easy to follow visually | Easy, but needs reading |
| Modification | Difficult — may need redrawing | Easy — just edit the text |
| Best for | Small problems, showing flow clearly | Large and complex problems |
| Space needed | Takes more space | Compact |
"Differentiate between a flowchart and pseudocode." — 2-mark question! Answer: A flowchart is a pictorial representation of an algorithm using standard symbols connected by arrows, while pseudocode is a textual, English-like representation of an algorithm that resembles program code but does not follow any language's syntax. Flowcharts are harder to modify; pseudocode is easier to modify.
7.5 🔀 Flow of Control
The flow of control is the order in which steps are executed. Every algorithm, however big, is built using just three basic control structures:
graph LR
FOC["🔀 FLOW OF CONTROL"]
SEQ["➡️ Sequence\nSteps one after\nanother"]
SEL["🔀 Selection\nChoose a path\nbased on a condition"]
REP["🔁 Repetition\nRepeat steps while\na condition is true"]
FOC --> SEQ
FOC --> SEL
FOC --> REP
style SEQ fill:#2196F3,color:#fff
style SEL fill:#FF9800,color:#fff
style REP fill:#4CAF50,color:#fff
7.5.1 Sequence ➡️
In a sequence, steps are executed one after another in the order in which they are written — no step is skipped or repeated.
Example — Convert temperature from Celsius to Fahrenheit:
INPUT C
COMPUTE F = C * 9 / 5 + 32
PRINT F
C = float(input("Enter temperature in Celsius: "))
F = C * 9 / 5 + 32
print("Temperature in Fahrenheit:", F)
# Input 100 → Temperature in Fahrenheit: 212.0
7.5.2 Selection 🔀
In selection (also called decision making or branching), the algorithm checks a condition and chooses one of two (or more) paths depending on whether the condition is True or False.
IF condition THEN
steps when condition is True
ELSE
steps when condition is False
Analogy: Selection is like a fork in the road 🛣️. If it's raining, take the covered road; otherwise, take the park road. You travel only ONE of the two roads!
Example 2 — Check whether a number is even or odd:
INPUT num
IF num MOD 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
graph TD
A(["Start"])
B[/"INPUT num"/]
C{"Is remainder of\nnum ÷ 2 equal to 0?"}
D[/"PRINT Even"/]
E[/"PRINT Odd"/]
F(["Stop"])
A --> B --> C
C -->|"Yes"| D --> F
C -->|"No"| E --> F
style A fill:#4CAF50,color:#fff
style C fill:#FF9800,color:#fff
style F fill:#F44336,color:#fff
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
# Input 7 → Odd
Example 3 — Find the largest of three numbers:
INPUT a, b, c
IF a > b AND a > c THEN
PRINT a, "is the largest"
ELSE IF b > c THEN
PRINT b, "is the largest"
ELSE
PRINT c, "is the largest"
graph TD
A(["Start"])
B[/"INPUT a, b, c"/]
C{"a > b AND a > c ?"}
D[/"PRINT a is largest"/]
E{"b > c ?"}
F[/"PRINT b is largest"/]
G[/"PRINT c is largest"/]
H(["Stop"])
A --> B --> C
C -->|"Yes"| D --> H
C -->|"No"| E
E -->|"Yes"| F --> H
E -->|"No"| G --> H
style A fill:#4CAF50,color:#fff
style C fill:#FF9800,color:#fff
style E fill:#FF9800,color:#fff
style H fill:#F44336,color:#fff
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a > b and a > c:
print(a, "is the largest")
elif b > c:
print(b, "is the largest")
else:
print(c, "is the largest")
# Input 12, 45, 30 → 45 is the largest
7.5.3 Repetition (Iteration) 🔁
In repetition (also called iteration or looping), a set of steps is executed again and again as long as a condition remains True.
Analogy: Repetition is like running laps on a track 🏃. You keep running "WHILE laps completed < 5". The moment you finish lap 5, the condition becomes False and you stop!
Example 4 — Find the sum of the first N natural numbers:
INPUT N
SET sum = 0
SET i = 1
WHILE i <= N
COMPUTE sum = sum + i
INCREMENT i by 1
PRINT sum
graph TD
A(["Start"])
B[/"INPUT N"/]
C["sum = 0\ni = 1"]
D{"i <= N ?"}
E["sum = sum + i\ni = i + 1"]
F[/"PRINT sum"/]
G(["Stop"])
A --> B --> C --> D
D -->|"Yes"| E
E --> D
D -->|"No"| F --> G
style A fill:#4CAF50,color:#fff
style D fill:#FF9800,color:#fff
style E fill:#2196F3,color:#fff
style G fill:#F44336,color:#fff
N = int(input("Enter N: "))
total = 0
i = 1
while i <= N:
total = total + i
i = i + 1
print("Sum =", total)
# Input 5 → Sum = 15
Forgetting to change the loop variable (e.g., missing INCREMENT i by 1) makes the condition stay True forever — an infinite loop! This breaks the Finiteness property of an algorithm.
Example 5 — Find the factorial of a number (N! = 1 × 2 × 3 × … × N):
INPUT N
SET fact = 1
SET i = 1
WHILE i <= N
COMPUTE fact = fact * i
INCREMENT i by 1
PRINT fact
N = int(input("Enter a number: "))
fact = 1
i = 1
while i <= N:
fact = fact * i
i = i + 1
print("Factorial =", fact)
# Input 5 → Factorial = 120
"Write an algorithm AND draw a flowchart to find the factorial / sum of N numbers / largest of three numbers." — 3 to 4-mark questions, asked very often!
Always: (1) start with Start and end with Stop, (2) initialise variables (sum = 0, fact = 1) before the loop, (3) draw the loop arrow going back to the decision box, and (4) label decision exits Yes / No.
7.6 ✅ Verifying Algorithms
Before coding, we must make sure the algorithm gives the correct output for every valid input. The simplest way is a dry run — executing the algorithm by hand, on paper, step by step, and recording the values of variables in a trace table.
Dry run of Example 4 (sum of first N natural numbers) for N = 5:
| Iteration | i (before step) | Condition i <= N |
sum = sum + i | i = i + 1 |
|---|---|---|---|---|
| 1 | 1 | True | 0 + 1 = 1 | 2 |
| 2 | 2 | True | 1 + 2 = 3 | 3 |
| 3 | 3 | True | 3 + 3 = 6 | 4 |
| 4 | 4 | True | 6 + 4 = 10 | 5 |
| 5 | 5 | True | 10 + 5 = 15 | 6 |
| — | 6 | False → loop ends | — | — |
Output: 15 ✅ — and we know 1 + 2 + 3 + 4 + 5 = 15, so the algorithm is correct for N = 5.
Normal Values
Test with typical inputs
N = 5N = 10Boundary Values
Test at the edges of valid input
N = 0N = 1Invalid Values
Check how it behaves with wrong input
N = -3N = "abc"A dry run catches logical errors early — like starting sum at 1 instead of 0, or using < instead of <= (which would miss the last number!). Fixing a mistake on paper is much cheaper than fixing it in a finished program.
7.7 ⚖️ Comparison of Algorithms
A problem can often be solved by more than one algorithm. We compare them to choose the most efficient one, using two measures:
Time Complexity
How much TIME (number of steps) the algorithm takes as the input grows
Fewer steps = fasterSpace Complexity
How much MEMORY the algorithm needs while running
Less memory = betterExample — Check whether a number N is prime:
A prime number has exactly two factors: 1 and itself (e.g., 2, 3, 5, 7, 11).
| Algorithm 1 | Algorithm 2 | |
|---|---|---|
| Idea | Divide N by every number from 2 to N − 1 | Divide N only by numbers from 2 to √N |
| Why it works | If none divides N exactly, N is prime | If N has a factor larger than √N, it must also have one smaller than √N |
| Divisions needed for N = 101 | 99 | 9 (from 2 to 10) |
| Efficiency | Slower | ✅ Much faster |
import math
N = 101
is_prime = N > 1
for d in range(2, int(math.sqrt(N)) + 1): # Algorithm 2: only up to √N
if N % d == 0:
is_prime = False
break
print(N, "is prime" if is_prime else "is not prime")
# 101 is prime
Analogy: Two routes can take you from home to school 🏫. Both reach the destination (correct output), but one takes 10 minutes and the other 40. A good programmer always looks for the shorter route!
"Why do we compare algorithms? On what basis?" — 2-mark question! Answer: Many algorithms can solve the same problem; we compare them to choose the most efficient one. Algorithms are compared on the basis of time complexity (processing time / number of steps) and space complexity (memory required).
7.8 💻 Coding
Coding is the process of converting an algorithm into a program using a programming language. The program written by the programmer is called the source code.
graph LR
ALG["📝 Algorithm\n(Flowchart /\nPseudocode)"]
SRC["💻 Source Code\n(Python program)"]
TR["⚙️ Translator\n(Interpreter)"]
MC["🔢 Machine Code\n(0s and 1s)"]
ALG -->|"Coding"| SRC --> TR --> MC
style ALG fill:#FF9800,color:#fff
style SRC fill:#2196F3,color:#fff
style MC fill:#4CAF50,color:#fff
Good coding practices:
- Choose meaningful variable names —
total_marks, nottm. - Add comments (
#) to explain tricky logic. - Keep proper indentation so the program is readable.
- Test the program with different kinds of input (normal, boundary, invalid).
Once the code is written, it goes through Testing and Debugging — you learnt about syntax, runtime and logical errors in the Data Handling chapter.
7.9 🧩 Decomposition
Decomposition means breaking a large, complex problem into smaller, simpler sub-problems that are easier to understand and solve. The solutions of the sub-problems are then combined to solve the original problem.
Example — Creating a "Student Report Card" system:
graph TD
BIG["🎓 Student Report Card System"]
S1["📥 Input student\ndetails and marks"]
S2["🧮 Calculate total\nand percentage"]
S3["🏅 Decide the grade"]
S4["🖨️ Print the\nreport card"]
BIG --> S1
BIG --> S2
BIG --> S3
BIG --> S4
style BIG fill:#9C27B0,color:#fff
style S1 fill:#2196F3,color:#fff
style S2 fill:#FF9800,color:#fff
style S3 fill:#4CAF50,color:#fff
style S4 fill:#F44336,color:#fff
Easier to Understand
Each small part can be understood on its own
Divide and conquerTeam Work
Different people can work on different parts at the same time
Faster developmentEasier Debugging
An error can be traced to one small part
Fix one part onlyReusability
A sub-solution (e.g. "calculate percentage") can be reused elsewhere
Write onceAnalogy: Planning your school's Annual Day 🎭 is a HUGE task. So it's decomposed: one team handles decoration, one handles the stage programme, one handles food, and one handles invitations. Each team solves a SMALL problem — together, the big event succeeds!
"What is decomposition? Explain with an example." — 2-mark question! Answer: Decomposition is the process of breaking a complex problem into smaller, manageable sub-problems that can be solved individually and then combined. Example: a report card system can be decomposed into inputting marks, calculating the percentage, deciding the grade, and printing the report.
⚠️ Common Errors and Misconceptions
| Mistake | What's Wrong | Correct Understanding |
|---|---|---|
| ❌ An algorithm and a program are the same | An algorithm has no language syntax | ✅ An algorithm is the step-by-step plan; a program is that plan written in a programming language |
| ❌ Using a rectangle for input/output in a flowchart | Wrong symbol | ✅ Input/Output uses a parallelogram; rectangle is for process |
| ❌ Using a diamond for Start/Stop | Wrong symbol | ✅ Start/Stop uses an oval (terminal); diamond is for decision |
| ❌ A loop without updating its variable | Loop never ends | ✅ Always change the loop variable (e.g., i = i + 1) to keep the algorithm finite |
❌ Starting fact at 0 for factorial |
Anything × 0 = 0 | ✅ Initialise fact = 1 (and sum = 0) |
| ❌ Pseudocode must follow Python syntax | It follows no language's syntax | ✅ Pseudocode is informal, English-like text |
| ❌ Testing only with one "normal" input | Hidden errors are missed | ✅ Test with normal, boundary and invalid inputs |
🔑 Quick Revision — Exam Ready!
Steps of Problem Solving (A-D-C-T):
- Analyse the problem → inputs, outputs, processing
- Develop an algorithm → step-by-step solution
- Code → write the program (source code)
- Test & Debug → run with different inputs, fix errors
Algorithm: A finite sequence of well-defined steps to solve a problem. Characteristics (PUFIO): Precision · Uniqueness · Finiteness · Input · Output
Flowchart Symbols:
| Symbol | Name | Use |
|---|---|---|
| Oval ⬭ | Terminal | Start / Stop |
| Rectangle ▭ | Process | Calculation / assignment |
| Diamond ◇ | Decision | Yes / No condition |
| Parallelogram ▱ | Input / Output | Read / Print |
| Arrow → | Flow line | Direction of flow |
| Circle ○ | Connector | Join parts of a flowchart |
Three Control Structures:
- Sequence → one step after another
- Selection → choose a path using a condition (IF-ELSE)
- Repetition → repeat steps while a condition is True (WHILE / FOR)
Other Key Terms:
- Dry run → executing an algorithm by hand using a trace table
- Time / Space complexity → basis for comparing algorithms
- Decomposition → breaking a big problem into smaller sub-problems
🎯 Sample Board Exam Questions
Q1: Very Short Answer [1 mark each]
a) Which flowchart symbol is used for a decision? → Diamond (◇)
b) Which flowchart symbol is used for input and output? → Parallelogram (▱)
c) Name the property of an algorithm which states that it must terminate after a finite number of steps. → Finiteness
d) What is a dry run? → Executing an algorithm manually, step by step, on paper to check its correctness
e) Name the three basic control structures used in algorithms. → Sequence, Selection and Repetition (Iteration)
Q2: Short Answer [2 marks]
Q: What is pseudocode? Write any two of its benefits.
Pseudocode is an informal, English-like way of writing an algorithm that looks similar to program code but does not follow the syntax of any programming language. Benefits: (1) It lets the programmer focus on the logic instead of language syntax. (2) It can be easily converted into a program in any programming language.
Q3: Algorithm [3 marks]
Q: Write an algorithm to check whether a person is eligible to vote (age 18 or above).
Step 1: Start
Step 2: INPUT age
Step 3: IF age >= 18 THEN
PRINT "Eligible to vote"
ELSE
PRINT "Not eligible to vote"
Step 4: Stop
Q4: Flowchart [3 marks]
Q: Draw a flowchart to print the numbers from 1 to 10.
graph TD
A(["Start"])
B["num = 1"]
C{"num <= 10 ?"}
D[/"PRINT num"/]
E["num = num + 1"]
F(["Stop"])
A --> B --> C
C -->|"Yes"| D --> E --> C
C -->|"No"| F
style A fill:#4CAF50,color:#fff
style C fill:#FF9800,color:#fff
style F fill:#F44336,color:#fff
Q5: Dry Run [3 marks]
Q: Dry run the following pseudocode for N = 4 and write the output.
INPUT N
SET fact = 1
SET i = 1
WHILE i <= N
COMPUTE fact = fact * i
INCREMENT i by 1
PRINT fact
Answer:
| i | Condition i <= 4 |
fact = fact * i |
|---|---|---|
| 1 | True | 1 × 1 = 1 |
| 2 | True | 1 × 2 = 2 |
| 3 | True | 2 × 3 = 6 |
| 4 | True | 6 × 4 = 24 |
| 5 | False → stop | — |
Output: 24
✏️ Practice Problems
-
List the four steps of problem solving and explain the "Analysing the problem" step with the example of calculating simple interest.
-
Write an algorithm and draw a flowchart to find the area and perimeter of a square.
-
Write pseudocode to check whether a number is positive, negative or zero.
-
Draw a flowchart to find the largest of two numbers.
-
Write an algorithm to print the multiplication table of a number entered by the user.
-
Write an algorithm and draw a flowchart to find the sum of all even numbers from 1 to N.
-
Differentiate between a flowchart and pseudocode (any three points).
-
Dry run the sum-of-N-natural-numbers algorithm for N = 3 using a trace table.
-
Two algorithms find whether a number is prime — one checks divisors up to N − 1 and the other up to √N. Which is better and why?
-
Decompose the problem "Online Library Management System" into at least four smaller sub-problems.