Igor Micev wrote:
> Hi Team,
>
> Such problems like yours are usually being solved with recursion
> algorithms. 
There are many version that do not use recursion though, such as the 
first algorithm I mentioned in my earlier reply. This is because back in 
the dark days of history, machines did not have enough stack spec to do 
much recursion so algorithms that did not need it were invented (they 
are slower of course). You can do limited amounts of recursion but to be 
honest, if it were me, I would just copy the C code for existing 
recursive algorithms and call it.

As you will know in advance how many elements to permute, then you just 
need to ask the C routines for the next permutation of 1,2,3,4,...n-1,n 
(the indexes into your array) and use these indexes to print the value 
at each index:

Assume you have:  AA^BB

Create the sequence 1,2

Loop while more permutations:
iteration 1 -
  get permute - it gives 1,2
  CRT s<1>, s<2>

Iteration 2 -
  get permute - it gives 2,1
  CRT s<2>, s<1>

If you use Heap's algorithm it will fit more neatly than a straight 
recursive solution though, otherwise you will have to compute.

Of course, a neater solution to avoid compute time is to pre-compute the 
permutations, store them in files, then READNEXT, READ, CRT the 
sequence. Because the files will be compact and read in hash order, 
there won;t be as much read overhead as you think, but there will be no 
recursions or calling C etc.

Anyway, lots of easy solutions for this.

Jim





--~--~---------~--~----~------------~-------~--~----~
Please read the posting guidelines at: 
http://groups.google.com/group/jBASE/web/Posting%20Guidelines

IMPORTANT: Type T24: at the start of the subject line for questions specific to 
Globus/T24

To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to