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. This guide applies that method to 15 solved examples across the common question shapes.
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. The exact question count, timing, and marking can change by hiring cycle and assessment route, and Infosys does not provide a single public syllabus for every drive. Confirm the instructions shown for your assessment instead of carrying fixed numbers from an old post.
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.
![the variable-trace table for the array scan. Columns i, arr[i], s, m. Rows: (0, 3, 3, 3), (1, 1, 4, 3), (2, 4, 8, 4), (3, 1, 9, 4), (4, 5, 14, 5). A final line "Output: 14 5" under the table.](https://kgai.blob.core.windows.net/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, including each nested-loop iteration.
Examples 4 to 15: the same method across archetypes
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.
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.
Adaptive scoring makes controlled early accuracy useful, but the exact marking rule must be confirmed in your assessment instructions.
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. Service-based companies placement prep: Accenture, Capgemini and Cognizant compared helps separate the shared core from company-specific stages.




