|
|
Sorting and Searching
A sorting algorythm rearranges elements of a
collection so that they are arranged in a sorted order.
A simple selection sort finds
the smallest element of a collection. It moves that to the front
location, and swaps the value at that location with the small
value. In other words, if we started with:
Our first iteration would give us:
(bold indicates swapped values).
On our next iteration, we would have:
No need to swap the 4 - it is already where it needs to be.
We continue with this process until we end up with:
This sort works correctly, and is easy to program. But, it is
slow and inefficient. It is given a factor of n2
performance.
Merge Sort
|