The Infosys pseudocode section is not a coding round. Treating it like one is why candidates lose marks on output, error, and missing-line questions. They trace in their heads, drop one variable update, and choose the confidently wrong option.
The fix is mechanical: write a variable-trace table and update it line by line. That one habit answers all three shapes the section sets, whether you are asked to predict the output, spot the error, or supply the missing line.
What the Infosys pseudocode section actually tests
Expect C-like pseudocode rather than code that must compile under a real language standard. The task may ask you to predict output, spot an error, or fill a blank so that the stated result appears. Syntax clues such as &, loop bounds, integer operations, and array indexes carry the answer.
Candidate reports commonly describe an adaptive flow, where a correct answer tends to lead to a harder next question. Question count, timing, and marking vary by hiring cycle and assessment route, so read the instructions on your own test screen before you start rather than working from numbers quoted second-hand.
Infosys placement preparation: test pattern, sections and a study plan places pseudocode beside the other test and interview parts.
The one technique: a variable-trace table
Draw one column for every variable that changes. Add a new row whenever a statement updates a value. For an array loop, include the index and current element. For a branch, record whether its condition was true. Never combine two iterations in your head.
For example, if s = s + arr[i] and then m may change, write the new s first and the new m second. This preserves execution order. A table takes seconds and prevents the common mistake of using a future value too early.
Example 1: trace an array scan
Integer arr[] = {3, 1, 4, 1, 5}
Integer s = 0, m = arr[0]
for i = 0 to 4 {
s = s + arr[i]
if arr[i] > m then m = arr[i]
}
Print s, mi | arr[i] | s after addition | m after comparison |
|---|---|---|---|
0 | 3 | 3 | 3 |
1 | 1 | 4 | 3 |
2 | 4 | 8 | 4 |
3 | 1 | 9 | 4 |
4 | 5 | 14 | 5 |
The sum is 3 + 1 + 4 + 1 + 5 = 14, and the largest value seen is 5. Output: 14 5.
![Variable-trace table for the array scan, with columns i, arr[i], s and m. Rows: (0, 3, 3, 3), (1, 1, 4, 3), (2, 4, 8, 4), (3, 1, 9, 4) and a highlighted final row (4, 5, 14, 5). A line under the table reads Output: 14 5.](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1784054111343_ue45v0.jpg)
Example 2: call-by-value vs call-by-reference
Integer a = 5, b = 8
swap(a, b)
Print a, b
Procedure swap(Integer &x, Integer &y) {
x = x + y
y = x - y
x = x - y
}The & markers mean x and y refer to the caller's variables.
Step | x | y | Caller state |
|---|---|---|---|
Entry | 5 | 8 |
|
| 13 | 8 |
|
| 13 | 5 |
|
| 8 | 5 |
|
Output: 8 5. If the parameters were passed by value, only local copies would change, so the caller would still print 5 8. One symbol flips the answer.
Example 3: trace recursion and loop counts
Function f(n) {
if n <= 1 then return 1
return n * f(n-1)
}
Print f(4)The calls descend before any multiplication completes:
f(4) = 4*f(3) = 4*3*f(2) = 4*3*2*f(1) = 4*3*2*1 = 24.
On return, the values are 1, 2, 6, and 24. Output: 24.

For loop-count questions, use the same discipline. Add a count column and increment it only when the innermost statement actually runs. In for i = 1 to 3 { for j = i to 3 { count = count + 1 } } the inner loop runs three times at i = 1, twice at i = 2 and once at i = 3, so count ends at 6, not 9.
Examples 4 to 15: the same method across question types
Each row below compresses a small trace table. The values after the arrows are the successive states you should write on paper.
Array scans and string handling
# | Pseudocode idea | Trace | Output |
|---|---|---|---|
4 | Count evens in |
|
|
5 | Sum |
|
|
6 | Count vowels in |
|
|
7 | Append |
|
|
Sorting and searching
# | Pseudocode idea | Trace | Output |
|---|---|---|---|
8 | Linear-search |
| index |
9 | Binary-search |
| index |
10 | One bubble pass on |
|
|
11 | Select minimum in |
|
|
Bits, parameters, and recursion
# | Pseudocode idea | Trace | Output |
|---|---|---|---|
12 | Count set bits using |
|
|
13 | Compute | binary |
|
14 | Pass | caller | caller prints |
15 |
|
|
|
These examples cover different syntax, but the work is identical: record state, execute one line, record state again. Do not jump directly from input to an intuitive output.
Error-spotting and missing-line questions
The same table answers the other two shapes. For an error question, trace until one line tries something the data does not allow. For a missing-line question, trace with the blank left empty and ask what single update would leave the stated result.
Example 16: spot the error
Integer arr[] = {4, 9, 2}
Integer total = 0
for i = 0 to 3 {
total = total + arr[i]
}
Print totalTrace it and the fault appears on the last row. total moves 0, 4, 13, 15 across indexes 0, 1 and 2, and then i reaches 3, where arr[3] does not exist: the array holds three elements at indexes 0, 1 and 2. The loop bound is the error, not the addition. Correct it to for i = 0 to 2 and the output is 15.
Example 17: supply the missing line
Integer n = 5, f = 1
for i = 1 to n {
______
}
Print fThe question states that the output is 120. Trace the blank as an unknown update: f must reach 120 after five iterations, and 120 is 5 factorial, so the missing line multiplies: f = f * i gives f as 1, 2, 6, 24, 120. The tempting alternative f = f + i is eliminated by tracing it too, because it gives 2, 4, 7, 11, 16.
Traps to mark before you calculate
Pre-increment vs post-increment:
++iproduces the incremented value;i++produces the earlier value before the increment takes effect.Integer division:
7 / 2becomes3when both operands are integers.Zero-based arrays: the first element is normally index
0in C-like questions.Inclusive bounds:
0 to noften meansn+1iterations, while0 to n-1meansn.Value vs reference: look for
&or explicit reference wording before tracing a procedure.
Because the flow adapts, your first few answers shape every question that follows. Trace those completely, even when the pseudocode looks trivial.
The short version and your next step
Always trace on paper. Give every changing variable a column, add a row for every update, and circle the reference marker before entering a procedure. That turns a rushed mental puzzle into bookkeeping.
Use the Infosys Superset Preparation course for structured practice and the Placement Preparation catalogue for the wider drive. For more output-prediction reps in a real language, work through Python Output-Based Questions: 13 Solved Snippets and predict each snippet before you read its explanation.




