@Kumar: As a point of interest, the number of valid sequences of n pushes
and n pops is C(3), the third Catalan Number. See, e.g.,
http://en.wikipedia.org/wiki/Catalan_number for details.
Dave
On Thursday, February 20, 2014 12:27:35 PM UTC-6, kumar raja wrote:
> Hi all,
>
> Here is a permuatation related question.
>
> Suppose the set is {a,b,c};
>
> At a given point of time either u can push an
> elemnt on to the stack or pop of the element.
> While pushing the elements u have to follow the
> order a,b,c as given in the set.
>
> When u pop the element u will print it to the
> output array.
>
> one possible sequence of operations is
>
> push(a),push(b),pop(),push(c),pop(),pop()
>
> The permuation obtained by above combination is
>
> {b,c,a}.
>
> But out of 6! permuations possible one invalid
> permutation is {c,a,b} (guess how?)
>
> So how to print all valid permuations with the
> above constaraints?
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].