Question discussion

The integers 1, 2, 3, 4 are pushed onto an initially empty stack in this order, and pops may be interleaved with the pushes at any time. Wh…

1771Medium DSSSB TGT Computer Science 0 replies 1 views
0

The integers 1, 2, 3, 4 are pushed onto an initially empty stack in this order, and pops may be interleaved with the pushes at any time. Which of the following output sequences is impossible?

  • A3 2 1 4
  • B4 3 2 1
  • C2 4 3 1
  • D3 1 2 4
Correct answer: D

Explanation

After 3 is popped the top of the stack is 2, so 2 must come out before 1; the sequence 3 1 2 4 is therefore impossible.

Discussion 0

Nobody has replied yet. Start the discussion!