GATE | GATE 2017 MOCK II | Question 22
Linked Questions 22-23
Stack A has the entries as following sequence a, b, c (with ‘a’ on top), stack B is empty, as shown in the diagram below.
An entry popped out of stack A can be printed or pushed to stack B. An entry popped out of stack B can only be printed.
In this arrangement which of the following permutation of a, b, c are not possible to print?
(i) bac (ii) bca (iii) cab (iv) abc
(A) (i), (ii) and (iii)
(B) (iv) Only
(C) (iii) Only
(D) (ii) and (iii) Only
Answer: (C)
Explanation: Follow these steps to print bac.
1) POP element ‘a’ from stack A, push ‘a’ to Stack B.
2) POP element ‘b’ from A, print it.
3) POP element ‘a’ from B, and print it.
4) POP element ‘c’ from A, and print it.
Now, permutation bac has been printed.
Similarly, we can print bca and abc, but can’t print cab.
Quiz of this Question
Please Login to comment...