Quick Sort

Quick Sort


Quick sort is speedy in its execution; it is one of the fastest algorithms presented so far, and happens to be the default sort method contained within many programming languages. The basic logic behind this algorithm is in ordering every element based on a pivot element. The script picks an initial element to be used as the pivot element. Then the list is reordered based on the pivot element, placing every element less than the pivot in one list and every element higher in another list. The median is the final spot for the pivot element. Once all elements have been ordered on this pivot, the process is repeated for each sublist. The algorithm is considered a divide-and-conquer sort.

The Code

 require 'benchmark' ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.