in DS recategorized by
434 views
3 votes
3 votes
Which of the following permutations can be obtained in the same order using a stack assuming that input is the sequence 5,6,7,8,9 in that order?

A ) 7,8,9,5,6
B ) 5,9,6,7,8
C ) 7,8,9,6,5
D ) 9,8,7,5,6
in DS recategorized by
434 views

1 comment

C is Right ans
0
0

2 Answers

3 votes
3 votes
Best answer
given the i/p sequence is 5,6,7,8,9

A) 7,8,9,5,6 ===> For getting 7, you should push 5 then push 6 therefore while poping 6 then 5 ===> This can't be the Answer

B) 5,9,6,7,8 ===> For getting 9, you should push 6 then push 7 therefore while poping 7 then 6 ===> This can't be the Answer

C) 7,8,9,6,5 ===> push 5, push 6, push 7, pop, push 8, pop, push 9, pop, pop,pop===> This can be the Answer

D) 9,8,7,5,6 ===> For getting 9, you should push 5 then push 6 therefore while poping 6 then 5 ===> This can't be the Answer

 

Option C is correct.
selected by
0 votes
0 votes
C) 7,8,9,6,5 ===> push 5, push 6, push 7, pop, push 8, pop, push 9, pop, pop,pop
by