Question: Use a stack to enumerate all permutations of a string. Suppose you want to find all permutations of the string meat. Push the string +meat
Use a stack to enumerate all permutations of a string. Suppose you want to find all permutations of the string meat. Push the string +meat on the stack. While the stack is not empty Pop off the top of the stack. If that string ends in a + (such as tame+) Remove the + and add the string to the list of permutations. Else Remove each letter in turn from the right of the +. Insert it just before the +. Push the resulting string on the stack. For example, after popping e+mta, you push em+ta, et+ma, and ea+mt.
Step by Step Solution
3.29 Rating (161 Votes )
There are 3 Steps involved in it
Here is an example of using a stack to enumerate all permutations of the strin... View full answer
Get step-by-step solutions from verified subject matter experts
