2,983 views
4 4 votes
How many permutations can be obtained in the output using a stack assuming that the input 1,2,3,4,5,6 such that 3 will be popped out from stack at 3rd position ?

1 Answer

3 3 votes

Case 1:
Push 1, pop 1
push 2, pop 2
push 3, pop 3

Case 2:
push 1
Push 2, Pop 2
Pop 1
push 3, pop 3


As we can see there 2 possibilities before 3(1, 2 and 2, 1), and there will be 4 possibilities after 3  (456, 546, and 564, 654,465).
so far we got 10 sequences.
Remaining 16 will be as follows:

4 5 3 2 1 6
4 5 3 2 6 1
4 5 3 6 2 1
5 4 3 2 6 1
5 4 3 6 2 1
5 4 3 2 1 6

143256

143265

143526

143562

143652

243156

243165

243516

243561

243651

Hence, there total 26 sequences possible.

• edited
Position:
Show:

Related questions

0 0 votes
2 2 answers
529
529 views
2 2 votes
2 2 answers
2.4k
2.4k views
Gurdeep Saini asked Jan 2, 2019
2,395 views
true/false ?) if stack is implemented as a array,all operation push ,pop ,is emptystack(),delete stack() can be performed in constant time.)if stack is implemented as a l...
1 1 vote
2 2 answers
1.5k
1.5k views
Shamim Ahmed asked Dec 11, 2018
1,458 views
Every recursive program uses strictly more stack space compared to its iterative equivalent.This statement is false. Please explain with examples
2 2 votes
0 0 answers
844
844 views
CHïntän ÞäTël asked Dec 7, 2018
844 views
I THING THERE IS MISTAKE BECAUSE BRACKET ARE CLOSING AFTER ELEMENT E SO ALL OPERATORS HOULD BE POPED AND AND ACCORDING TO ME ANWER SHOLD BE 2…TRY AND CORRECT IF I M WRON...