Re: [algogeeks] permutations using a stack

2012-10-23 Thread neeraj bagga
http://en.wikipedia.org/wiki/Catalan_number On Sun, Oct 21, 2012 at 4:00 PM, Shruti Gupta wrote: > if n=1,2,3 n we denote Push by "P" and Pop by "X" > the we can generate following permutations : > > 1) PPPXXX = 321 > 2) PPXXPX = 213 > 3) PXPXPX = 123 > 4) PXPPXX = 132 > 5) PPXPXX = 231 > > condi

[algogeeks] permutations using a stack

2012-10-21 Thread Shruti Gupta
if n=1,2,3 n we denote Push by "P" and Pop by "X" the we can generate following permutations : 1) PPPXXX = 321 2) PPXXPX = 213 3) PXPXPX = 123 4) PXPPXX = 132 5) PPXPXX = 231 conditions : #P's = #X's and At no point, #X's>#P's Ques :- Given n elements, find the number of permutations which are