Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

GATE | GATE-IT-2004 | Question 52

  • Last Updated : 28 Jun, 2021

A program attempts to generate as many permutations as possible of the string, ‘abcd’ by pushing the characters a, b, c, d in the same order onto a stack, but it may pop off the top character at any time. Which one of the following strings CANNOT be generated using this program?
(A) abcd
(B) dcba
(C) cbad
(D) cabd


Answer: (D)

Explanation:  

A. PUSH a- POP a , PUSH b- POP   b , PUSH c- POP   c, PUSH d- POP   d

B. PUSH a ,PUSH b, PUSH c,PUSH d , POP d, POP c ,POP b, POP a   

C.PUSH a ,PUSH b, PUSH c , POP c ,POP b, POP a   PUSH d- POP   d

D. Sequence not feasible

Therefore,Answer is D

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!