The Gateway to Computer Science Excellence
+1 vote
791 views

If we have six stack operationspushing and popping each of $A, B$ and $C$-such that push $(A)$ must occur before push $(B)$ which must occur before push $(C)$, then $A, C, B$ is a possible order for the pop operations, since this could be our sequence : push $(A)$, pop $(A)$, push $(B)$, push $(C)$, pop $(C)$, pop $(B)$. Which one of the following orders could not be the order the pop operations are run, if we are to satisfy the requirements described above?

  1. $ABC$
  2. $CBA$
  3. $BAC$ 
  4. $CAB$
in DS by Boss (30.8k points)
recategorized by | 791 views

2 Answers

+1 vote
As question says, push (A) (A) must occur before push (B) (B)which must occur before push (C)

So option a is valid as

first push A than pop A

Than push B again pop B

Than push C again pop c

So here ABC is valid pop sequence

(B)option

Push A

Push B

Push C

Pop all we will get CBA sequence so its valid

Option (c)

Push A

Push B  now pop B than again pop C  now push C now pop C

So  BCA is valid sequence

(D) option is not valid

So( d) option answer
by Boss (20.1k points)
0 votes

Below is the dependency graph

by Boss (11.5k points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,292 answers
198,230 comments
104,911 users