Cycle sort is based on the idea that array to be sorted can be divided into cycles, which can individually be rotated to give a sorted result.
More...
Cycle sort is based on the idea that array to be sorted can be divided into cycles, which can individually be rotated to give a sorted result.
It is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of memory writes to the original array. Each value is either written zero times, if it’s already in its correct position, or written one time to its correct position.
The array is divided into cycles. We begin with the cycle containing the first element. Find the correct position of first element and place it at its correct position, say j. Now we consider the old value of arr[j] and find its correct position. This process is continued until all the elements of the current cycle are placed at their correct position, i.e. until the starting point of the cycle is reached.
- Author
- Vasu Sehgal
- See also
- more on Cycle sort