ProgrammingVery hardWipro · TCS NQT pattern
What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?
What is the final content of the stack (bottom to top, left to right) after this sequence of operations on an initially empty stack?
push 47 push 50 pop push 47 push 19 push 28 push 10 push 93
- A. 47, 47, 19, 28, 10
- B. 47, 47, 19, 28, 10, 93
- C. 93, 10, 28, 19, 47, 47
- D. 50, 47, 19, 28, 10, 93
Correct answer: B. 47, 47, 19, 28, 10, 93
Tracing push/pop on an empty stack in order gives, bottom-to-top, [47, 47, 19, 28, 10, 93]. Reading top-to-bottom instead gives the reversed trap [93, 10, 28, 19, 47, 47]; mistakenly treating "pop" as removing the front (as in a queue) gives [50, 47, 19, 28, 10, 93].
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What is the final content of the queue (front to back, left to right) after this sequence of operations on an initially empty queue?…
- Consider this naive recursive Fibonacci. How many TOTAL calls to fib (including the initial call) happen when computing fib(5)? Function…
- What will be the output of the following pseudocode? (Arrays are passed and assigned BY REFERENCE: b = a makes b point to the same array…
- What will be the output of the following pseudocode? (^ is bitwise XOR.) Integer x = 90, y = 62 x = x ^ y y = x ^ y x = x ^ y Print x, y
- What will be the output of the following pseudocode? (A square matrix's main diagonal is mat[i][i]; its anti-diagonal is mat[i][n-1-i]. If…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Function f(Integer n, Integer…