Quicksort

Published September 13, 1999 by Yin-So Chen, posted by Myopic Rhino
Do you see issues with this article? Let us know.
Advertisement
Now that we visit a recursive sorting algorithm. This algorithm involves moving a data, called pivot. The algorithm then partitions the array into two parts by moving the pivot into its correct position, so that items to the pivot's left are smaller then the pivot, and the items to the right are bigger.The algorithm then is called recursively so that it will partition the two subordinate arrays on either side of the pivot until the entire array is sorted.

Below is the pseudo-code of Quick Sort.

Quick Sort (Sorting array A[size])

While Low is less than High
{
Choose Pivot as the element at position A[Low]
While A[High] is greater than Pivot, decrement High; else move A[High] to A[Low]
While A[Low] is less than Pivot, increment Low; else move A[Low] to A[High]
}
Move Pivot into A[High], see Pivot position as High.
If Low is less than Pivot point, recursively call Quick Sort with Low =
Low, High = Pivot point - 1
If High is greater than Pivot point, recursively call Quick Sort with Low =
Pivot point + 1, High = High.

Cancel Save
0 Likes 0 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

The quicksort is the fastest known comparison-based sorting algorithm, with a growth rate of O (n log n) on average. However, in the worst case, this degrades to O (n[sup]2[/sup]), but this can be mostly avoided if implemented carefully.

Advertisement
Advertisement