-1

Can anyone suggest specific algorithms to find different permutations of a given string except recursion technique

  • If you want iteration, instead of recursion, note that every solution which can be written as a recursion can be written in an iterative way as mentioned by Amnon Shochot in an answer below. So I would recommend you write down the recursive algorithm and then work out the iterative solution. – Aravind Apr 05 '15 at 11:47

2 Answers2

0

You can find how to do it with recursion in here.

Then you can port this code to use stacks instead of relying on the thread stack used by the recursion.

Community
  • 1
  • 1
Amnon Shochot
  • 8,998
  • 4
  • 24
  • 30
0

A solution to this problem, if you don't want to use recursion, can be via dynamic programming, something like this:

list = originalString.split('')
index = (0,0)
list = [""]
for iteration n in 1 to y:
  index = (index[1], len(list))
  for string s in list.subset(index[0] to end):
    for character c in originalString:
      list.add(s + c)
Ice
  • 64
  • 1
  • 7