Infosys Pseudocode Questions: How to Trace Them Fast, with Solved Examples

Stop tracing pseudocode in your head. Use one repeatable table for output, error, and fill-in questions, with 15 solved examples across common archetypes.

Prashant Jain

KnowledgeGate AI educator

Updated 15 Jul 20265 min read

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, m

i

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.

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

a=5, b=8

x = x + y

13

8

a=13, b=8

y = x - y

13

5

a=13, b=5

x = x - y

8

5

a=8, b=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.

the recursion call stack for f(4). Downward push arrows f(4) -> f(3) -> f(2) -> f(1), then upward pop arrows returning 1, then 21=2, then 32=6, then 4*6=24, with the final Output 24 at the top.

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 {2,5,8,9}

count: 0 -> 1 -> 1 -> 2 -> 2

2

5

Sum {6,2,1} from index 2 down to 0

s: 0 -> 1 -> 3 -> 9

9

6

Count vowels in "CODE"

i: 0,1,2,3; v: 0 -> 0 -> 1 -> 1 -> 2

2

7

Append "CAT"[i] for i=2 down to 0

out: "" -> "T" -> "TA" -> "TAC"

TAC

Sorting and searching

#

Pseudocode idea

Trace

Output

8

Linear-search 7 in {4,7,9}

i=0: no; i=1: yes

index 1

9

Binary-search 11 in {2,5,8,11,14}

(l,h,m): (0,4,2) -> (3,4,3)

index 3

10

One bubble pass on {3,1,2}

{3,1,2} -> {1,3,2} -> {1,2,3}

{1,2,3}

11

Select minimum in {5,2,4}, then swap first

min: 0 -> 1 -> 1; swap indexes 0,1

{2,5,4}

Bits, parameters, and recursion

#

Pseudocode idea

Trace

Output

12

Count set bits using n = n & (n-1), start n=12

(n,c): (12,0) -> (8,1) -> (0,2)

2

13

Compute 10 & 6

binary 1010 & 0110 = 0010

2

14

Pass a=7 by value to inc(p){p=p+1}

caller a=7; local p: 7 -> 8

caller prints 7

15

sum(n)=0 at n=0, else n+sum(n-1); call sum(3)

3+2+1+0

6

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: ++i produces the incremented value; i++ produces the earlier value before the increment takes effect.

  • Integer division: 7 / 2 becomes 3 when both operands are integers.

  • Zero-based arrays: the first element is normally index 0 in C-like questions.

  • Inclusive bounds: 0 to n often means n+1 iterations, while 0 to n-1 means n.

  • 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.

Keep learning

TCS NQT Coding Questions 2026: Pattern-Wise Solutions in Python and Java

TCS NQT coding questions grouped into six recurring patterns, from digit logic to array scans, each solved step by step in Python and Java with variants.

19 Jul 20267 min readPlacement Preparation

Technical interview prep: OS, DBMS, CN and OOP questions freshers face

Coding is only half of a technical interview. The other half is the core computer science subjects, and this is where freshers who "only did DSA" get caught. The good news is that the fresher-level questions on Operating Systems, DBMS, Computer Networks and Object-Oriented Programming are remarkably

Updated 14 Jul 20265 min readPlacement Preparation

Resume for freshers: build a CS resume that clears the first screen

Your resume has one job, and it is not to impress. It is to survive the first screen: a recruiter spending a few seconds per resume, and often an automated filter before that. A CS fresher resume that clears both is not the fanciest one. It is the clearest one. This guide is about building that clea

17 Jul 20264 min readPlacement Preparation

HR interview questions for freshers: how to answer the standard ones honestly

The HR round is where offers are lost by people who already cleared the hard part. You solved the coding round, you survived the technical interview, and then a calm conversation about yourself trips you up. Not because the questions are hard, but because you never prepared honest answers to questio

17 Jul 20264 min readPlacement Preparation

Discussion