There are n
different elements,
already know the order each element is pushed in.
How many different kinds of combination can there be for the poping order?
EDIT
In fact I know there are 2n!/(n+1)n!^2 combinations,but why?
There are n
different elements,
already know the order each element is pushed in.
How many different kinds of combination can there be for the poping order?
EDIT
In fact I know there are 2n!/(n+1)n!^2 combinations,but why?
A stack can be popped in only a single order -- the reverse of the order the elements were pushed.
Suppose your elements are called A, B, C, ... and pushed in that order.
Let P(X) mean "Push X" and O(X) mean "Pop X"
Let N be the number of elements.
So what are the pop orders?
Possibilities when N=1: P(A)O(A). (i.e. "A")
Possibilities when N=2: P(A)P(B)O(B)O(A). ("BA") P(A)O(A)P(B)O(B). ("AB")
Possibilities when N=3: ABC and BAC (from above, followed by P(C)O(C).) CBA. (from P(A)P(B)P(C)O(C)O(B)O(A).) But not CAB, since if "C" comes off first, it must have gone on last, so nothing else has come off yet, so they can only come off in the order BA.
Building from that pattern, you should be able to construct and solve a recurrence relation that gives the answer you need.
Nice one Eric. However, when I tried with ABC, I got 4 possibilities, ABC, BAC, BCA and CBA.
Pity the formula presented is not clear, because I can't make n=3 give an answer of 4 from simple interpretations of what was written above.
Induction would seem to be the answer to proving the formula (as it often is when the question is of the form "prove that ... is given by formula ...").
And there is a certain symmetry in the four possibilities above, which makes me think it might not be too difficult to come up with the answer.
EDIT: Actually, can't we get ACB also? AaBCcb. Where uppercase letters are a push, lowercase a pop. So, 5 possibilities, CAB is definitely not possible.