1/18
Loading...
🚀Start Cyclic Sort
This array holds values 1..5. Each value v has a fixed home at index v-1. We sort by sending out-of-place values straight home.
Loading...
This array holds values 1..5. Each value v has a fixed home at index v-1. We sort by sending out-of-place values straight home.
Cyclic sort exploits the fact that in an array of values 1..n, each value has a fixed home (index = value - 1). If the value we are looking at is not at home, we send it straight there; if it is, we move on.