O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Quicksort

Invented by Professor C.A.R. Hoare in 1961, quicksort has proven to be the best general-purpose sorting algorithm. Many computer languages offer a library version, and PHP uses it for its built-in sorting functions. It is based on the same idea of exchanging elements, but adds the concept of partitioning. In most implementations it relies on recursion, a topic discussed in Chapter 4.

The quicksort algorithm chooses a pivot element and then divides all elements by whether they are greater or lesser than the pivot. Each subsection is further divided similarly. When the granularity becomes small enough, elements are simply compared and possibly swapped, as in the bubble sort.

When we first call the quicksort function in Listing 15.2, we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required