Re: [algogeeks] permutations using stack

2012-10-21 Thread Saurabh Kumar
answer is right there in the strings: S = PPXXPXPXPPX... Possible permutations = No. of ways to generate strings of P/X's such that in each sub-string S[0..i] no. of P's is always greater than or equal to no. of X's. You can also view this as - all possible strings of n balanced parentheses. This

[algogeeks] permutations using stack

2012-10-21 Thread Shruti
we can generate permutations using stack. For example, if n=1,2,3 and Push() is denoted by "P", and Pop() by "X", then we can generate permutations as : PPPXXX = 321 PPXXPX = 213 PXPXPX = 123 PXPPXX = 132 PPXPXX = 231 (note : at any point, #P's>=#X's and finally, #P's=#X's) ques :- Given n eleme