GATE | GATE-IT-2004 | Question 52

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
Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.