Follow-up Comment #1, bug #51104 (project gsl):

from rsmith =at= whistlin =dot= com

I think Pavel Sinitcyn's code gives a more literal translation of step L3 in
Knuth's description of the algorithm ("Algorithm L" in AoCP vol 4, page 319).
The change decreases the running time by over 10% in my tests.  I haven't
tested for accuracy, though.

Incidentally, the existing version of gsl_permutation_next() in
permutatiion.c
has a superfluous check in the boolean expression on line 155:

    (p->data[j] > p->data[i]) && (p->data[j] < p->data[k])

The while loop starting on line 141 guarantees that p->data[j] < p->data[k]
for
i<k<j (Knuth explains this in step L3).  But I think the slow down is caused
by
the structure of the for loop, which seems awkward compared to the
straightforward textbook version.

Regis

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51104>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


Reply via email to