ProgrammingHardGoldman Sachs OA · Infosys SP
What will be the output of the following pseudocode? (Arrays are indexed from 0)
What will be the output of the following pseudocode? (Arrays are indexed from 0)
Integer nxt[6] = {3, 5, 0, 1, 2, 4}
Integer x = 0, steps = 0
do
x = nxt[x]
steps = steps + 1
while (x != 0)
Print steps- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: D. 6
Follow the links from 0: 0 → 3 → 1 → 5 → 4 → 2 → 0. The walk returns to 0 after 6 steps, so all six indices lie on one cycle.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[6] = {4, 5, 2, 25, 7, 8}, res[6] Stack st =…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer h[12] = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code) String s = "PROGRAMMING", r = "" Boolean…
- What will be the output of the following pseudocode? String s = " the quick brown fox " Integer words = 0 Boolean inWord = false for (each…
- What will be the output of the following pseudocode? Integer val[7] = {1000, 500, 100, 50, 10, 5, 1} String sym[7] = {"M", "D", "C", "L"…
- What will be the output of the following pseudocode? (code(c) gives a character's code; 'A' to 'Z' have consecutive codes) String a =…