Pseudo Code: Concepts, Formulas, and Clear Examples
Pseudo-code MCQs trace loops, conditionals, variables, and functions without compiling. Syntax resembles C/Java/Python hybrid; focus on control flow and update order (when i increments, what prints).
Use a trace table: columns for variables each line. Watch off-by-one in for loops, integer division, and scope of updates inside nested ifs.
Loop tracing
- for i = 1 to n inclusive vs i < n—check bounds on first and last iteration.
- while loops: condition checked before body (usually).
Example — Sum loop
sum=0 for i=1 to 3 sum = sum + i end → sum = 6.
Conditionals and nesting
- else binds to nearest if without braces—follow indentation in stem.
- Boolean: AND short-circuit may skip side effects in some languages—read note in question.
Functions and parameters
Pass by value copies; changes inside function may not affect caller unless return assigned.
Arrays and indexing
- 0-based vs 1-based—question usually states base.
- Length n → valid indices 0..n-1 (0-based).
Complexity from pseudo-code
- Single loop to n → O(n); nested → O(n²); halving loop → O(log n).
Common traps
- Integer division 5/2 = 2.
- Modulo on negatives—follow specified language rule or avoid in simple items.
Step-by-step method for exam questions
- List variables and initial values.
- Execute line-by-line; update trace table.
- On loops, note exit condition before assuming termination.
- For functions, push separate frame for parameters.
- After trace, match output or final variable to options.
- If complexity asked, count dominant loop iterations.
Formula cheat sheet
| Situation | Formula | When to use |
|---|---|---|
| for 1 to n | n iterations | Inclusive bound |
| while i<n | Stops at i=n-1 last body | 0-based walk |
| Nested loops same n | O(n²) | Complexity |
| Integer / | Truncates toward zero | C-like pseudo |
| Swap via temp | 3 assignments | Trace swap |
Frequently asked questions
Exact language?
Follow conventions stated in question header.
Recursion depth?
Trace small n manually; watch base case return.
Print vs return?
Output MCQs care about print order; variable MCQs about final value.
Practice on this platform
Use 4 practice sets (10 MCQs, detailed solution after each answer) and 2 timed mocks (20 minutes) on this topic to convert formulas into speed and accuracy.