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
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, perumtation bac has been printed.
Similarly, we can print bca and abc, but can’t print cab.
Quiz of this Question
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.