Pseudo Code by Yash Sir: Core Rules and Two Worked Traces

Learn how to read pseudo code precisely, track changing state and verify two complete traces covering array selection, integer arithmetic and nested loops.

KnowledgeGate Team

Exam prep & CS education

Updated 28 Nov 20266 min read
Pseudo Code by Yash Sir: Core Rules and Two Worked Traces

Pseudo Code by Yash Sir: Core Rules and Two Worked Traces

Pseudo code looks simple until one unclear symbol, loop bound or update order changes the output. Fix a notation contract, dry-run changing state, and check an array-and-branch trace plus a nested-loop trace with exact intermediate values. Reason from written rules instead of memorising one language's syntax, while Company-Specific Placement Courses provide a wider placement-preparation route.

1. Pseudo code is an algorithm notation, not a programming language

Pseudo code is a readable, language-neutral description of an algorithm's data, decisions, repetition and output. It is precise enough to trace, but it is not compiled and has no single standards body. Different conventions work when they are declared and followed consistently.

Artifact

Job

Example

Problem statement

Defines the required result

Double every even value and add selected odd values

Algorithm

Decides the ordered steps

Inspect each value, choose one branch, update totals

Pseudo code

Expresses those steps readably

Use FOR, IF, MOD and assignment on A=[7,2,9,4,6]

Source program

Implements the algorithm

Write equivalent C, C++ or Python code

Changing braces or keywords can preserve the algorithm. Changing > to >= can change its meaning. Notation is flexible, logic is not.

2. Pseudo code rules must be declared before a trace

Arrays are zero-indexed. x <- value assigns a value; = tests equality inside a condition. FOR i <- 0 TO 4 includes 0 and 4. For these positive integers, MOD returns the non-negative remainder and DIV the integer quotient. IF, ELSE IF and ELSE are mutually exclusive. Statements run top to bottom unless control flow redirects them.

Notation

Exact example

Input and output

READ n; PRINT score

Assignment

score <- score + 7

Comparison

score = 40

Selection

IF value > 5

Iteration

FOR i <- 0 TO 4

Array access

A[i]

Integer quotient

40 DIV 3 = 13

Remainder

40 MOD 3 = 1

Precedence is parentheses; multiplication, DIV and MOD; addition and subtraction; comparisons; NOT; AND; then OR. With x=5, y=2, z=3, x + y * z = 5 + 2 * 3 = 5 + 6 = 11, while (x + y) * z = 7 * 3 = 21. Other questions may set different symbols or bounds. Follow the stated contract.

3. Dry-running pseudo code means tracking only changing state

Use four steps. First, box the initial values and operator rules. Second, mark every decision and loop bound. Third, make one column for each changing variable. Fourth, execute exactly one statement at a time. Saying that a loop "finds the answer" is not a trace because it hides intermediate updates.

Start the trace with A=[7,2,9,4,6], score=0 and evenCount=0. The trace columns will be i, A[i], branch taken, score after iteration and evenCount after iteration. Keep immutable input outside repeated cells. Record score=7 immediately after the first iteration, and never increment evenCount on an odd branch. Pseudocode Questions for Placements: 3 Solved Traces gives further array, string and loop practice using the same discipline.

4. Worked example 1: trace selection, an array and integer arithmetic

Code
A <- [7, 2, 9, 4, 6]
score <- 0
evenCount <- 0

FOR i <- 0 TO 4
    IF A[i] MOD 2 = 0 THEN
        score <- score + 2 * A[i]
        evenCount <- evenCount + 1
    ELSE IF A[i] > 5 THEN
        score <- score + A[i]
    END IF
END FOR

PRINT score DIV evenCount
PRINT score MOD evenCount

i

A[i]

Branch taken and update

score after iteration

evenCount after iteration

0

7

Odd and 7>5, add 7

7

0

1

2

Even, add 2*2=4

11

1

2

9

Odd and 9>5, add 9

20

1

3

4

Even, add 2*4=8

28

2

4

6

Even, add 2*6=12

40

3

40 DIV 3 = 13 because 3*13=39; 40 MOD 3 = 1 because 40=3*13+1. The printed lines are 13 and 1.

Check independently: 7 + 4 + 9 + 8 + 12 = 40, and even values 2, 4 and 6 give evenCount=3. Since 6 enters the even branch, the mutually exclusive ELSE IF cannot add it again.

Flowchart and trace table for A = [7, 2, 9, 4, 6], showing mutually exclusive branches, score and evenCount updates, and outputs 13 and 1.

5. Worked example 2: count a triangular nested loop

The following nested loops expose the loop bounds and update order:

Code
steps <- 0
value <- 0

FOR row <- 1 TO 3
    FOR col <- 1 TO row
        steps <- steps + 1
        value <- value + row + col
    END FOR
END FOR

PRINT steps, value

row

col

steps after update

Value added

value after update

1

1

1

2

2

2

1

2

3

5

2

2

3

4

9

3

1

4

4

13

3

2

5

5

18

3

3

6

6

24

The inner loop runs 1+2+3=6 times. Its additions are 2+3+4+4+5+6=24, so the output is 6, 24. When row=3, the inner loop has three iterations, not two, because TO row is inclusive under the declared contract. Showing the execution order first makes both totals checkable without jumping to a formula.

Triangular nested-loop diagram showing six execution cells for rows 1 through 3, cumulative steps 6, value 24, and final output.

6. Pseudo code traps that change the answer

Each wrong answer below comes from breaking a declared convention. Fix the convention first, then recompute.

Trap

Wrong assumption

Correct consequence

Assignment

Treat score <- score + 4 as an equation

With score=7, the new score is 11

Inclusive bound

Stop the loop at index 3

Value 6 is omitted, leaving score=28, evenCount=2, output 14, 0

Precedence

Read score + 2*A[i] as (score+2)*A[i] at i=1

The wrong value is (7+2)*2=18; the contract gives 7+2*2=11

Branch structure

Replace ELSE IF with an independent IF

Value 6 adds an extra 6, giving score=46, evenCount=3, output 15, 1

Two more checks matter. DIV gives integer 13, while real division 40/3 gives 13.333.... With zero-based indexing, A[4] is the fifth value, 6, not an out-of-range sixth value.

7. How pseudo code questions test reading, not memorisation

Common forms ask you to predict output, identify a branch, fill a missing update, compare IF with ELSE IF, count nested-loop iterations or change a boundary input. Practice questions on this subtopic still reward the same discipline: the reasoning method matters more than surface syntax.

Test retrieval with three checks:

  1. Replace A[3]=4 with A[3]=5. The +8 even contribution disappears, leaving score=32 and evenCount=2, so the program prints 16, 0.

  2. How often does the nested-loop body run? Six times.

  3. What if the second condition is an independent IF? The array score becomes 46 because 6 is added twice.

For company-context practice, use Infosys Pseudocode Questions: 17 Solved Traces and Traps. Follow each question's conventions instead of assuming fixed syntax or pattern.

8. Pseudo code in one checklist and the next step

Remember five steps: declare conventions; mark bounds and branches; initialise changing state; execute one statement at a time; verify the output with an independent sum or iteration count. The array trace ends at score=40, evenCount=3 and prints 13, 1; the triangular loop performs six updates and ends at 24.

Now change one input or loop bound and rewrite every affected row. If you want a structured pseudo-code practice route, INFOSYS Superset is the relevant next step.