Q.Following is an algorithm to classify numbers as “Single Digit”, “Double Digit” or “Big”.
Classify_Numbers_Algo
INPUT Number
IF Number < 9
"Single Digit"
Else If Number < 99
"Double Digit"
Else
"Big"
Verify for (5, 9, 47, 99, 100 200) and correct the algorithm if required
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Testing the boundary values exposes the bug: with Number < 9 and Number < 99, the inputs 9 and 99 are misclassified — the conditions must be <= 9 and <= 99.
The idea (verification and boundary testing). An algorithm is verified by dry-running it on test data — and the most revealing test values are the boundaries between categories. Here the categories are single digit (1–9), double digit (10–99) and big (100+), so the values 9 and 99 sit exactly on the edges — and that is precisely where the given algorithm breaks. (The list "(5, 9, 47, 99, 100 200)" is read as the six values 5, 9, 47, 99, 100, 200 — the missing comma is a book misprint.)
Dry run of the algorithm as printed
| Number | IF Number < 9 | Else IF Number < 99 | Output | Expected | Verdict |
|---|---|---|---|---|---|
| 5 | 5 < 9 → true | — | Single Digit | Single Digit | ✓ |
| 9 | 9 < 9 → false | 9 < 99 → true | Double Digit | Single Digit | ✗ |
| 47 | false | 47 < 99 → true | Double Digit | Double Digit | ✓ |
| 99 | false | 99 < 99 → false | Big | Double Digit | ✗ |
| 100 | false | false | Big | Big | ✓ |
| 200 | false | false | Big | Big | ✓ |
Four of six pass; the two boundary values 9 and 99 fail because strict < excludes the boundary itself.
Corrected algorithm
Classify_Numbers_Algo (corrected)
INPUT Number
IF Number <= 9
"Single Digit"
Else If Number <= 99
"Double Digit"
Else
"Big"
Python verification of the corrected version
for Number in [5, 9, 47, 99, 100, 200]: …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.