Data Structures & AlgorithmsVery hardGATE CS · Product placement

Items E, F, G, H, I, J are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?

  1. A. E H G I F J
  2. B. G E F H I J
  3. C. F G I H E J
  4. D. E G H I J F

Correct answer: B. G E F H I J

Simulate greedily: push until the needed item is on top, then pop. In G E F H I J, when E must be popped, F is on top of it (pushed later and not yet popped), so E cannot come out. The other sequences pass the simulation.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic