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

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 |
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 |
|
Assignment |
|
Comparison |
|
Selection |
|
Iteration |
|
Array access |
|
Integer quotient |
|
Remainder |
|
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
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
|
| Branch taken and update |
|
|
|---|---|---|---|---|
0 | 7 | Odd and | 7 | 0 |
1 | 2 | Even, add | 11 | 1 |
2 | 9 | Odd and | 20 | 1 |
3 | 4 | Even, add | 28 | 2 |
4 | 6 | Even, add | 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.](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1786710339847_3zfbu9.jpg)
5. Worked example 2: count a triangular nested loop
The following nested loops expose the loop bounds and update order:
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
|
|
| Value added |
|
|---|---|---|---|---|
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.

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 | With |
Inclusive bound | Stop the loop at index 3 | Value 6 is omitted, leaving |
Precedence | Read | The wrong value is |
Branch structure | Replace | Value 6 adds an extra 6, giving |
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:
Replace
A[3]=4withA[3]=5. The+8even contribution disappears, leavingscore=32andevenCount=2, so the program prints16, 0.How often does the nested-loop body run? Six times.
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.
Keep learning
C Programming by Yash Sir Formula Sheet: Rules, Traces and Revision Notes
Revise C through compact rules, use cues and checked traces. The sheet covers expressions, loops, arrays, functions, storage and dynamic memory.
AMCAT Computer Programming Module Revision Map: Code, DSA and Core CS
Revise programming and core CS as separate problem types. This map shows the state, invariant, dependency or timeline to write before choosing an answer.
C Language Concepts Interview Questions and Answers: Model Answers, Code Traces and Traps
Prepare for C interviews by learning how to explain types, aliases, arrays, storage and allocation, then trace exact values without inventing output for invalid code.
Iterative Loops in C for GATE: Code Traces, Worked Examples and Exam Traps
Learn a mechanical method for tracing C loops. Work through exact values, invariants, nested-loop counts, complexity, termination bugs, and output traps.





