© 1997 by British Computer Society
An Analysis of Two In-Place Array Rotation Algorithms
Department of Computer Science, Michigan Technological University, Houghton, MI 49931-1295, USA Email: shene{at}mtu.edu
This paper presents a complexity analysis of two STL in-place rotation algorithms. If an array of n elements is rotated to the right
positions, the first STL version, which uses forward iterators, used n gcd(n,
) swaps, while the second version, which uses random access iterators, uses only n+gcd(n,
) array elements movements. This paper also proves the optimality of the second version. A performance comparison is included.
Received January 20, 1997. revised January 16, 1998.