[Solved] permutations of string in ascending order [closed]


In your example the strings are not in ascending order: you have AB, AC, AD, ABC, …, but then you have B, BC before C, and D. If you want it in alphabetical order should be A, AB, ABC, ABCD, AC, ….

When you write it that way you see the recursive structure … just take the A off the first half of the list and you should get the second. So you can easily write a recursive program that does something like

permute("ABCD"):
  print ("A" + everything in permute("BCD"))
  print (everything in permute("BCD")) 

solved permutations of string in ascending order [closed]