GATE CSE
First time here? Checkout the FAQ!
x
+7 votes
197 views

Loading Question

asked in DS by Veteran (12.2k points) 9 73 138
retagged by | 197 views
Nice question ..But time taking before arriving at a conclusion.
Yes. The only way i am knowing is by writing all permutations. I want to know if it can be solved by some logic.
In such questions as I said earlier you have to do what is mentioned in the question and solve accordingly.This was the confusion which I had earlier.Let me rectify

1 Answer

+8 votes
Best answer

This is a problem whose soltution lies in Catalan number.In this case for any permutation no of pushes >= no of pops for any prefix of permutaion 

So 5th Catalan no is given by :   2nC/ (n+1)

                                          =   10C5 / 6

                                          =   42

Hence the answer to this question should be 42.

Plz refer to the link :

http://math.stackexchange.com/questions/17769/using-one-stack-to-find-number-of-permutations

answered by Veteran (88.2k points) 15 58 293
selected by
Answer is correct. But how do you conclude this formula.??

Try to do with 3  numbers . 

The number of permutation is equal to no. of post-order of binary search tree . since with 3 nodes number of binary search tree are 2nC/ (n+1) .

Of course the formula is correct. But this question is fill in the blank type. Ijust want to know how such conclusion can be obtained.
i already give you hint try with small number then you idea .
It is analogous to balanced parantheses problem with prefix property.Check for it u will get the idea .Only the difference is instead of opening and closing brackets , we are using push and pop here.
Thank you guys.
I dont know who has downvoted my comment and for what reason..It is better to give valid argument also if one is downvoting.

One does not become great by simply downvoting..If one want to show skill , then give legitimate comments ..I have no problem..

But don't do this silly thing..


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
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users