GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 1.14

A stack permutation

Data Structures · Stacks & Queues · Full GATE CSE 1994 paper

GATE 1994, Q1.14 MCQ
Report issue

Stacks & Queues

Question 1.14, GATE 1994: Input 1,2,3,4,5 arrives in order. Which output is possible with one stack: 34512,34521,15234,54312?
Tap to enlarge
Your answer
Answer & solution

Answer: B: 34521 (no official key was published)

Step through it (4 options)

Push 1,2,3 and pop 3; push 4 and pop 4; push 5 and pop 5; then pop 2 and 1. This constructs 34521. For 34512, after producing 345 the stack has 2 above 1, so 1 cannot come next. For 15234, after popping 1 then pushing through 5, the next available value is 4, not 2. For 54312, after popping 5,4,3, value 2 still blocks 1. Thus only B is feasible.

Original paper, page 2