+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
recategorized | 791 views

+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

by Boss (20.1k points)

Below is the dependency graph  by Boss (11.5k points)

+1 vote