Stack A has the entries a, b, c (with a on top). Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of the stack B can be only be printed. In this arrangement, which of the following permutations of a, b, c are not possible?
Question
Stack A has the entries a, b, c (with a on top). Stack B is empty. An entry popped out of stack A can be printed immediately or pushed to stack B. An entry popped out of the stack B can be only be printed. In this arrangement, which of the following permutations of a, b, c are not possible?
Solution
The permutation that is not possible is "c, a, b".
Here's why:
-
"c, a, b" would require 'c' to be the first one to be printed. But 'c' is at the bottom of stack A and we can't get to it without first popping 'a' and 'b'.
-
We could push 'a' and 'b' to stack B, but according to the rules, once an entry is popped out of stack B, it can only be printed.
-
So, we can't push 'a' and 'b' to stack B to get to 'c' because we would have to print 'b' before we could print 'a'.
-
Therefore, the permutation "c, a, b" is not possible under these rules.
Similar Questions
Stack M has the entries 1,2,3(with a on top).Stack N is empty.An entry popped out of stack M can be printed immediately or pushed to stack N.An entry popped out of the stack N can only be printed. In this arrangement, which of the following permutations of 1,2,3 are not possible?Options3,1,21,2,32,1,33,2,1
Which of the following permutations can be obtained in the output(in the same order),using a stack assuming that the input is the sequence A,B,C,D,E in that order?OptionsC,D,E,A,BC,D,E,B,AC,D,A,B,EC,D,A,E,B
Select the correct answerStack M has the entries 1,2,3(with a on top).Stack N is empty.An entry popped out of stack M can be printed immediately or pushed to stack N.An entry popped out of the stack N can only be printed. In this arrangement, which of the following permutations of 1,2,3 are not possible?Options1,2,32,1,33,2,13,1,2
If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, in what order will they be removed?
Consider the following operations performed on a stack of size 5 : Push (a); Pop() ; Push(b); Push(c); Pop(); Push(d); Pop();Pop(); Push (e) Which of the following statements is correct?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.