AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started

Topic

Pseudocode aptitude questions

Trace the loop, print the output — the section Infosys and Wipro lean on.

0 of 40 solved in this view

Formula sheetPseudocode: the essentialsFormula sheetPseudocode: the essentialsShow

Read the question's own conventions before tracing a single line.

Conventions to confirm

  • Whether / is integer division, discarding the fraction, and MOD the remainder: 17 / 5 = 3 and 17 MOD 5 = 2.
  • Whether arrays and strings are 0-indexed or 1-indexed. An n-element 0-indexed array ends at n − 1.
  • 'For i = a to b' includes both ends; with step s it runs ⌊(b − a)/s⌋ + 1 times.
  • While tests before the body and may run zero times; Repeat … Until tests after, runs at least once and stops when its condition becomes true.
  • Break leaves the loop; Continue skips to the next pass. An Else If ladder runs only the first true branch.
  • By value passes a copy; by reference passes the caller's variable itself.

Tracing

  • Keep a trace table: one column per variable, one row per pass.
  • Nested loops whose inner bound is the outer counter run n(n + 1)/2 times, not n².
  • For recursion, write each pending expression on the way down and substitute on the way up. The base case counts as a call.
  • Recognise stock routines: n MOD 10 with n / 10 peels digits; (a, b) → (b, a MOD b) is Euclid's GCD; a = a + b, b = a − b, a = a − b swaps; n MOD 2 with n / 2 counts binary 1s; two indices closing in test for a palindrome.

Questions40

1

Adding the even numbers

What does the following pseudocode print?

for loop · accumulator

60s

Easy
2

Halving until one

In the pseudocode below / is integer division: any fraction is discarded. What is printed?

while loop · integer division

90s

Medium
3

Counting inner iterations

How many times does the statement Set c = c + 1 execute?

nested loops

75s

Medium
4

Swapping without a third variable

What does the pseudocode print?

swapping · tracing

60s

Easy
5

Which branch fires

What value of grade is printed?

conditionals

45s

Easy
6

Position of the largest element

The array A is 1-indexed, so its elements are A[1] to A[6]. What is printed?

arrays · 1-indexed

75s

Easy
7

Walking an array backwards

The array A is 0-indexed, so its elements are A[0] to A[4]. What is printed, in order?

arrays · 0-indexed

60s

Easy
8

Counting vowels

Characters are numbered from 1, so s[1] is the first character. What does this print?

strings · counting

60s

Easy
9

Recursion that steps by two

What is printed?

recursion

90s

Medium
10

How many calls are made

Counting the first call from the main program, how many times is G invoked in total?

recursion · counting

75s

Medium
11

Call by value

Parameters are passed by value. What is printed, in order?

functions · call by value

75s

Medium
12

One by reference, one by value

The parameter marked ref is passed by reference; the other is passed by value. What does the program print?

functions · call by reference

90s

Medium
13

What does this routine compute

For positive integers a and b, what does Mystery(a, b) return?

routine purpose · gcd

90s

Medium
14

Reversing a number

/ is integer division and MOD is the remainder. What is printed?

while loop · digits

75s

Easy
15

Repeated multiplication

What is printed?

for loop · accumulator

60s

Easy
16

A loop that steps by seven

How many times does the body of the loop execute?

for loop · counting

60s

Easy
17

Leaving the loop early

What is printed?

while loop · break

105s

Medium
18

A post-tested loop

A Repeat ... Until loop tests its condition after running the body. What is printed?

do while · loop semantics

75s

Medium
19

Sum over an upper triangle

What is printed?

nested loops · tracing

105s

Medium
20

A product that keeps getting trimmed

What is printed?

for loop · accumulator

90s

Easy
21

Multiples of three or four

What is printed?

for loop · counting

120s

Hard
22

One pass of a bubble sort

The array A is 0-indexed. What are the contents of A after the loop?

arrays · sorting

120s

Medium
23

How many swaps does it perform

The array A is 0-indexed. What is printed?

sorting · counting

150s

Hard
24

Comparisons in a linear search

The array A is 1-indexed. How many times is the comparison A[i] == key evaluated?

arrays · searching

105s

Medium
25

Iterations of a binary search

A is 1-indexed and holds A[i] = 10 × i, that is 10, 20, 30, ..., 150. / is integer division. What is printed?

searching · tracing

150s

Hard
26

Reversing a string in place

Characters are numbered from 1 and / is integer division. What is printed?

strings · swapping

150s

Hard
27

Identify the test

Characters are numbered from 1. What does Check(s) decide?

routine purpose · strings

90s

Medium
28

Adding the digits

/ is integer division and MOD is the remainder. What is printed?

while loop · digits

60s

Easy
29

Skipping the diagonal

What is printed?

nested loops · continue

75s

Easy
30

Read, transform, print

The program is run with the inputs a = 6 and b = 14, in that order. What is printed?

tracing · swapping

90s

Medium
31

Rotating three variables

What is printed?

swapping · tracing

75s

Medium
32

Counting remainders on division by two

/ is integer division. What is printed?

while loop · binary

120s

Hard
33

Rotating an array left

The array A is 0-indexed. What are its contents at the end?

arrays · rotation

90s

Medium
34

Which diagonal is being added

The matrix M is 1-indexed in both dimensions. What is printed?

matrix · nested loops

105s

Medium
35

What is being returned

The array A is 1-indexed and holds n elements. What does F(A, n, x) return?

routine purpose · arrays

75s

Easy
36

A condition that is never met

What is printed?

while loop · infinite loop

135s

Hard
37

Two routines calling each other

What is printed?

recursion · tracing

150s

Hard
38

Continue and Break in one loop

What is printed?

for loop · break · continue

105s

Medium
39

Tracking two extremes at once

The array A is 0-indexed. What is printed?

arrays · tracing

90s

Medium
40

Counting steps to one

/ is integer division. How many times does the body of the loop run?

while loop · tracing

180s

Hard

Showing 40 of 40

Pseudocode Aptitude Questions with Solutions

40 Pseudocode questions with hints, worked solutions and time targets — 13 easy · 19 medium · 8 hard.

  • Section: Programming MCQs
  • Questions: 40
  • By difficulty: 13 easy · 19 medium · 8 hard
  • Cost: Free, unlimited on every plan

Trace the loop, print the output — the section Infosys and Wipro lean on.

Pseudocode: the essentials

Read the question's own conventions before tracing a single line.

Conventions to confirm

  • Whether / is integer division, discarding the fraction, and MOD the remainder: 17 / 5 = 3 and 17 MOD 5 = 2.
  • Whether arrays and strings are 0-indexed or 1-indexed. An n-element 0-indexed array ends at n − 1.
  • 'For i = a to b' includes both ends; with step s it runs ⌊(b − a)/s⌋ + 1 times.
  • While tests before the body and may run zero times; Repeat … Until tests after, runs at least once and stops when its condition becomes true.
  • Break leaves the loop; Continue skips to the next pass. An Else If ladder runs only the first true branch.
  • By value passes a copy; by reference passes the caller's variable itself.

Tracing

  • Keep a trace table: one column per variable, one row per pass.
  • Nested loops whose inner bound is the outer counter run n(n + 1)/2 times, not n².
  • For recursion, write each pending expression on the way down and substitute on the way up. The base case counts as a call.
  • Recognise stock routines: n MOD 10 with n / 10 peels digits; (a, b) → (b, a MOD b) is Euclid's GCD; a = a + b, b = a − b, a = a − b swaps; n MOD 2 with n / 2 counts binary 1s; two indices closing in test for a palindrome.

Questions

  1. Adding the even numbers Easy
    What does the following pseudocode print?
  2. Halving until one Medium
    In the pseudocode below / is integer division: any fraction is discarded. What is printed?
  3. Counting inner iterations Medium
    How many times does the statement Set c = c + 1 execute?
  4. Swapping without a third variable Easy
    What does the pseudocode print?
  5. Which branch fires Easy
    What value of grade is printed?
  6. Position of the largest element Easy
    The array A is 1-indexed, so its elements are A[1] to A[6]. What is printed?
  7. Walking an array backwards Easy
    The array A is 0-indexed, so its elements are A[0] to A[4]. What is printed, in order?
  8. Counting vowels Easy
    Characters are numbered from 1, so s[1] is the first character. What does this print?
  9. Recursion that steps by two Medium
    What is printed?
  10. How many calls are made Medium
    Counting the first call from the main program, how many times is G invoked in total?
  11. Call by value Medium
    Parameters are passed by value. What is printed, in order?
  12. One by reference, one by value Medium
    The parameter marked ref is passed by reference; the other is passed by value. What does the program print?
  13. What does this routine compute Medium
    For positive integers a and b, what does Mystery(a, b) return?
  14. Reversing a number Easy
    / is integer division and MOD is the remainder. What is printed?
  15. Repeated multiplication Easy
    What is printed?
  16. A loop that steps by seven Easy
    How many times does the body of the loop execute?
  17. Leaving the loop early Medium
    What is printed?
  18. A post-tested loop Medium
    A Repeat ... Until loop tests its condition after running the body. What is printed?
  19. Sum over an upper triangle Medium
    What is printed?
  20. A product that keeps getting trimmed Easy
    What is printed?
  21. Multiples of three or four Hard
    What is printed?
  22. One pass of a bubble sort Medium
    The array A is 0-indexed. What are the contents of A after the loop?
  23. How many swaps does it perform Hard
    The array A is 0-indexed. What is printed?
  24. Comparisons in a linear search Medium
    The array A is 1-indexed. How many times is the comparison A[i] == key evaluated?
  25. Iterations of a binary search Hard
    A is 1-indexed and holds A[i] = 10 × i, that is 10, 20, 30, ..., 150. / is integer division. What is printed?
  26. Reversing a string in place Hard
    Characters are numbered from 1 and / is integer division. What is printed?
  27. Identify the test Medium
    Characters are numbered from 1. What does Check(s) decide?
  28. Adding the digits Easy
    / is integer division and MOD is the remainder. What is printed?
  29. Skipping the diagonal Easy
    What is printed?
  30. Read, transform, print Medium
    The program is run with the inputs a = 6 and b = 14, in that order. What is printed?
  31. Rotating three variables Medium
    What is printed?
  32. Counting remainders on division by two Hard
    / is integer division. What is printed?
  33. Rotating an array left Medium
    The array A is 0-indexed. What are its contents at the end?
  34. Which diagonal is being added Medium
    The matrix M is 1-indexed in both dimensions. What is printed?
  35. What is being returned Easy
    The array A is 1-indexed and holds n elements. What does F(A, n, x) return?
  36. A condition that is never met Hard
    What is printed?
  37. Two routines calling each other Hard
    What is printed?
  38. Continue and Break in one loop Medium
    What is printed?
  39. Tracking two extremes at once Medium
    The array A is 0-indexed. What is printed?
  40. Counting steps to one Hard
    / is integer division. How many times does the body of the loop run?

Placement tests that ask pseudocode