Generate all permutation

Pages: 12
That last code, K will never be < 1. So you have an infinite loop. You are not properly keeping your K variable in check.

http://www.bearcave.com/random_hacks/permute.html

You should study the 3 algorithms on here. There is no need to re-invent the wheel unless you really have to.
sugest me the abandon problem and i accept that is not exist non-recursive method for this simple problem? The solution exist, and help me to generalize that for other backtracking problem.
Non-Recursive Permutations:
http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz

Download and read that. He has an example of a non-recursive permutation algo.


i suggest here that for all recursive solution must exist a nonrecursive. The recursive solution exist if the program that is use that recursion function run on machine with poor memory.
I have this article, it is theoretical one. But what is solution for my program to change my program?
http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz
That has an example of a non-recursive solution.

I actually have some code that will generate all permutations at home, I am 99% sure that it's non-recursive. But I'd have to check it tonight. I will have a check of it when I get home from work. I used it for a structural steel application I developed a few years ago.

1) you have the code for this program?
2) if you read this article, you observe than Knuth try to construct the tree (in solution space) in some way
Last edited on
I can have a look at it tonight and see if it is non-recursive. It was a limited solution in that it was only viable to generate all permutations for upto 30(ish) objects before the time to compute it became quite significant.
not time is important , but the dimension of recurssion stack that is use
Ok. I will check my code tonight and let you know if it is recursive or non-recursive.

Z.
Ok. Unfortunately my code does something different. Giving a list of objects it tells you every possible unique combination you can make by joining those objects together.

e.g
1-4 would be
1
12
13
14
123
1234
2
23 etc etc

You are going to have to read through http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz to get your answer.
Topic archived. No new replies allowed.
Pages: 12