Permuting in place: analysis of two stopping rules

  • Authors:
  • Alois Panholzer;Helmut Prodinger;Marko Riedel

  • Affiliations:
  • Institut für Algebra and Computermathematik, TU Wien, Wiedner Hauptstr, 8-10, 1040 Wien, Austria;The John Knopfmacher Centre for Applicable Analysis and Number Theory, School of Mathematics, University of the Witwatersrand, P.O. Wits, 2050 Johannesburg, South Africa;EDV, Neue Arbeit gGmbH, Presselstr. 29, 70191 Stuttgart, Germany

  • Venue:
  • Journal of Algorithms
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Permuting in place has been first analyzed by Knuth. It uses the cycle structure of the permutation. The elements of an array to be permuted are only moved when one sees a cycle leader (smallest element in its cycle). So the essential part of such an algorithm is to test an element i about whether it is a cycle leader.Recently, Keller [Inform. Process. Lett. 81 (2002) 119-125] introduced two stopping rules: "If the last cycle leader has been detected, all elements have been moved, and no further tests are necessary" (heuristic 1), respectively "If only r elements have not been moved, then proceeding along a cycle is only useful for r steps" (heuristic 2).We analyze the average costs of these modifications applied to the standard algorithm of Knuth; they are (n + 2)Hn - 5n/2 - 1/2 ∼ n log n and respectively ((2n + 1)/4)H|(n-1)/2| + (1/2)H2⌊(n+1)/2⌋ - (1/2)(⌊(n + 1)/2⌋ - ⌊n/2⌋) - (n+1)/2 ∼ (n/2) log n, as opposed to (n + 1)Hn - 2n ∼ n logn in the classical case.