Data Structures · Question 29 · Hard
Data Structures question 29
The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may happen at any time in between. Each popped number is printed. Which output sequence is NOT possible?
- 3 2 5 4 1
- 4 5 3 2 1
- 4 3 5 1 2
- 2 1 4 3 5
Answer and explanation
Answer: C. 4 3 5 1 2
Explanation: After 4, 3 and 5 are popped, the stack still holds 1 and 2 with 2 on top, so 2 must come out before 1. The output 4 3 5 1 2 is impossible, while the other three sequences can all be produced.
Previous: The keys 10, 20, 30, 25, 28 are inserted in that order into an empty AVL tree… · Next: A max-heap of 15 distinct keys is stored in array positions 1 to 15. How many…
Practise data structures
Try a fresh set of data structures questions with an explanation after every answer, free and without signing up: Data Structures practice. Or sit a full placement mock test.
More data structures questions
- An array-based binary min-heap holds [2, 5, 3, 9, 6, 4, 8]. One deleteMin…
- A binary tree has preorder traversal A B D E H C F G and inorder traversal D B…
- The keys 10, 20, 30, 25, 28 are inserted in that order into an empty AVL tree…
- A max-heap of 15 distinct keys is stored in array positions 1 to 15. How many…
More technical & programming practice
Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge