Company LogoCompany Logo
Company LogoCompany Logo
Back to Technical

Pseudo Code

    • Theory
    • Set 1
    • Set 2
    • Set 3
    • Set 4
    • Set 1
    • Set 2
  1. Aptitude
  2. Technical
  3. Pseudo Code
  4. Theory

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

  1. List variables and initial values.
  2. Execute line-by-line; update trace table.
  3. On loops, note exit condition before assuming termination.
  4. For functions, push separate frame for parameters.
  5. After trace, match output or final variable to options.
  6. If complexity asked, count dominant loop iterations.

Formula cheat sheet

SituationFormulaWhen to use
for 1 to nn iterationsInclusive bound
while i<nStops at i=n-1 last body0-based walk
Nested loops same nO(n²)Complexity
Integer /Truncates toward zeroC-like pseudo
Swap via temp3 assignmentsTrace 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.

Start practiceAll Technical topics