Dry Run, Comparing Algorithms and Decomposition Class 11 Computer Science
Updated 17 October 2026 · Fact-checked
A dry run traces an algorithm by hand with sample inputs, recording the values of variables after each step, to check that it gives the correct output (including boundary values). Two algorithms for the same problem are compared by the number of steps they take. Decomposition breaks a large problem into smaller sub-problems that are solved separately and combined.
Write the pair after every pass; when b becomes 0, the value of a (here 6) is the answer, matching the expected GCD.
Illustration drawn for QuestionBuddy.
Understand Dry Run, Comparing Algorithms and Decomposition
Dry run. Choose test inputs (typical and boundary values), make a table of variables and write their values after each step. Compare the final output with the expected result. Boundary tests: smallest and largest allowed values, zero, equal values.
Example (Euclid's algorithm for GCD). Algorithm: while b is not 0, replace (a, b) by (b, a mod b); the answer is a. For a = 48, b = 18: (48, 18), then (18, 12), then (12, 6), then (6, 0). The answer is 6. Three passes.
Comparing algorithms. The same problem can have more than one algorithm. The better algorithm needs fewer steps (less time) and less memory. Example: testing whether n = 97 is prime. Algorithm 1 tries every divisor from 2 to 96, which is 95 divisions. Algorithm 2 tries divisors only while d x d <= n, that is 2 to 9, which is 8 divisions. Both give the same answer (97 is prime) but Algorithm 2 is about twelve times quicker for this case.
Decomposition. Break a big problem into modules. Example: preparing a result sheet: (1) input marks of each subject; (2) calculate total; (3) calculate percentage; (4) decide grade; (5) print the sheet. Each module can be written and tested separately, teams can share the work, and errors are easier to find.
Types of errors found by a dry run. Syntax errors (language rules) are found by the translator; logical errors (wrong result) show up in a dry run; run-time errors (such as division by zero) occur during execution.
Coding. After the algorithm is verified, it is coded in a programming language, then tested and debugged.
Dry Run, Comparing Algorithms and Decomposition: key facts
- Dry run
- Choose inputs
- Tabulate variables step by step
- Compare output with the expected result
- Test boundary values
- Manual verification.
- Comparing algorithms
- Fewer steps is better
- Less memory is better
- Same output for same input
- Efficiency.
- Decomposition
- Break into sub-problems
- Solve each
- Combine results
- Modular design.
- Errors
Syntax language rules Logical wrong result Run-time failure during execution - Three kinds.
How to answer Dry Run, Comparing Algorithms and Decomposition questions
A dry-run table is the heart of most questions on this topic.
- 1List the variables as columns.
- 2Write the initial values in the first row.
- 3Execute each step and write the new values in the next row.
- 4Stop when the loop condition fails; read the output.
- 5For comparison questions, count the passes or divisions for each algorithm.
Dry Run, Comparing Algorithms and Decomposition in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Checking a divisor search
Suppose a student tests if 97 is prime by dividing by every number from 2 to 96.
How can a smarter test reduce the work?
Try it first, then show the solutionSolution
- Any factor pair has one factor not more than the square root of 97 (about 9.8).
- So testing divisors 2 to 9 is enough: 8 divisions.
Answer: 8 divisions instead of 95.
Memory hook: Stop at the square root.
Tricks to remember Dry Run, Comparing Algorithms and Decomposition
Short memory aids. Say each one aloud once, then use it on a question the same day.
Table the variables
A dry run is a table with one column per variable.
Use it when: Dry run.
Break to build
Decompose first, then solve each piece.
Use it when: Decomposition.
Dry Run, Comparing Algorithms and Decomposition: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Purpose · 1 mark · MCQBoard level
The main purpose of a dry run is to:
(a) speed up the computer
(b) check an algorithm with sample data by hand
(c) translate a program
(d) store data
Try it first, then show the solutionSolution
- Manual tracing.
Answer: (b) check an algorithm with sample data by hand
Example 2: Dry run table · 3 marks · Short answerBoard level
Perform a dry run of Euclid's algorithm for a = 48, b = 18 and give the GCD. (3 marks)
Try it first, then show the solutionSolution
- Pass 1: (48, 18): 48 mod 18 = 12, so (18, 12).
- Pass 2: (18, 12): 18 mod 12 = 6, so (12, 6).
- Pass 3: (12, 6): 12 mod 6 = 0, so (6, 0). b is 0: stop, GCD = a = 6.
Answer: GCD = 6.
Example 3: Comparing two algorithms · 4 marks · Short answerHarder board level
To test whether 97 is prime, Algorithm 1 divides by all numbers from 2 to 96, and Algorithm 2 divides only by numbers d with d x d not greater than 97. Count the divisions in each and state which is better and why. (4 marks)
Try it first, then show the solutionSolution
- Algorithm 1: 96 − 2 + 1 = 95 divisions.
- Algorithm 2: d = 2 to 9 (9 x 9 = 81, 10 x 10 = 100 > 97): 8 divisions.
- Both conclude that 97 is prime.
- Algorithm 2 is better because it reaches the same result in far fewer steps.
Answer: 95 versus 8 divisions; Algorithm 2 is better.
Example 4: Decomposition · 4 marks · Short answerHarder board level
A school wants a program that prepares the result sheet of a class. Decompose the problem into at least four sub-problems and give two benefits of decomposition. (4 marks)
Try it first, then show the solutionSolution
- Sub-problems: (1) input marks of each student; (2) calculate the total; (3) calculate the percentage; (4) determine the grade; (5) print the report.
- Benefit 1: each module is smaller and easier to write and test.
- Benefit 2: different people can work on different modules, and errors are easier to locate.
Answer: Input, total, percentage, grade, print; easier testing and shared work.
Example 5: Boundary test · 5 marks · Short answerHOTS / competency
An algorithm to find the average of N numbers is: INPUT N; sum = 0; repeat N times: INPUT x, sum = sum + x; PRINT sum / N. Perform a dry run for N = 3 with 4, 8, 6 and identify a boundary input for which the algorithm fails. (5 marks)
Try it first, then show the solutionSolution
- N = 3: sum goes 4, 12, 18. Output = 18 / 3 = 6.
- Boundary input N = 0: no numbers are read and sum / N is 0 / 0, a division by zero (a run-time error).
- The algorithm should check IF N > 0 before dividing.
Answer: Average 6; fails for N = 0 (division by zero).
Where students lose marks in Dry Run, Comparing Algorithms and Decomposition
The slips examiners see most often, and what to write instead.
Mistake: Skipping the table
Doing the run in your head.
Wrong working
Answer: 6 with no steps.
Right working
Show a row for every pass.
Do this: Marks are for the steps.
Usually costs: 1 to 2 marks
Mistake: Only testing normal inputs
Not trying boundary values.
Wrong working
Tests N = 3 only.
Right working
Also tests N = 0 and N = 1.
Do this: Boundary inputs reveal errors.
Usually costs: 1 mark
Mistake: Calling logical errors syntax errors
Mixing error types.
Wrong working
Wrong average is a syntax error.
Right working
Wrong result is a logical error.
Do this: Syntax errors break language rules.
Usually costs: 1 mark
Exam tips
- Show the dry run as a table with one row per pass.
- Always test at least one boundary value.
- In comparison questions give the number of steps for each algorithm.
- List decomposition modules as a numbered list.
Practice questions on Dry Run, Comparing Algorithms and Decomposition
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
A logical error is found by:
(a) the compiler
(b) the interpreter before running
(c) testing and dry running
(d) the keyboardHint
The result is wrong.
Answer
(c) testing and dry running
Q2 · 3 marks · Short answerHarder board level
Perform a dry run of Euclid's algorithm for 84 and 36. (3 marks)
Hint
84 mod 36 = 12.
Answer
(84, 36) gives (36, 12) since 84 mod 36 = 12. (36, 12) gives (12, 0) since 36 mod 12 = 0. GCD = 12.
Q3 · 4 marks · Short answerHarder board level
To test whether 101 is prime, Algorithm A divides by every number from 2 to 100 and Algorithm B divides only by d while d x d is not more than 101. Count the divisions in each and compare. (4 marks)
Hint
Largest d with d x d <= 101 is 10.
Answer
Algorithm A: 100 − 2 + 1 = 99 divisions. Algorithm B: d = 2 to 10 (10 x 10 = 100 <= 101 but 11 x 11 = 121 > 101): 9 divisions. Both conclude that 101 is prime; B needs 9 instead of 99 divisions.
Q4 · 1 mark · Assertion-reasonHarder board level
Assertion (A): Decomposition makes a large problem easier to solve.
Reason (R): Each sub-problem can be solved and tested separately.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
Modular design.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q5 · 5 marks · Short answerHOTS / competency
An algorithm for the average of marks reads marks until -1 is entered and prints sum / count. Dry run the input 70, 90, -1 and the input -1 only. Identify the problem with the second input and suggest a fix. (5 marks)
Hint
Count can be zero.
Answer
For 70, 90, -1: sum = 160, count = 2, average = 80. For -1 only: count = 0, so sum / count is a division by zero. Fix: IF count > 0 THEN PRINT sum / count ELSE PRINT "No marks entered".
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What is a dry run?Show answer
Tracing an algorithm by hand with sample data.
2.What does decomposition do?Show answer
Breaks a problem into smaller sub-problems.
3.GCD of 48 and 18?Show answer
6.
4.Which is better: fewer steps or more steps?Show answer
Fewer steps.
5.Which error does a dry run find?Show answer
Logical errors.
Dry Run, Comparing Algorithms and Decomposition: frequently asked questions
Why test boundary values?
Errors often occur at the smallest or largest allowed input.
Is decomposition only used in programming?
No, it is a general problem-solving technique.
Can two correct algorithms give the same output?
Yes, but one may be much faster.