Open In App

GATE | GATE-IT-2004 | Question 52

Like Article
Like
Save
Share
Report

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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads