Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the real name of median sort and/or where can I find more material on it

I'm reading the book Algorithms in a Nutshell published by O'Reilly Media and I was reading the section on sorting algorithms and found one called Median Sort. Since I had never heard of it before and my textbook from CS3 (which covered algorithms) did not have it listed, I googled it and tried looking it up on Wikipedia and found nothing. I would greatly appreciate it if someone could provide the name I could easily look the algorithm up under or point me to other resources about it. Thank you.

Also, from what I can tell about the algorithm, it's essentially Quicksort except it always uses the median value as the pivot. By median value I mean it seems to scan the array of items and pick the middle value as the pivot, not pick the middle item in the array as the pivot. Also, the book mentions a Blum-Floyd-Pratt-Rivest-Tarjan (BFPRT) in relation to the "Median" sort.

like image 480
mnuzzo Avatar asked Aug 23 '10 03:08

mnuzzo


Video Answer


1 Answers

Most versions of quicksort pick (for example) the median of three elements (typically the first, middle and last), giving what's normally called a median of 3 Quicksort. Just starting with the middle element as the pivot doesn't usually qualify for any name other than just Quicksort.

Edit (much later, after seeing the edit in the question): it appears that what you're talking about is using the "median of medians" algorithm to choose the pivot element for a QuickSort. The median of medians algorithm is better known for being used independently as an alternative to (or refinement of, depending on your viewpoint) Hoare's Select algorithm. This is known to find the median (or other rank, but in this case we only care about median) in linear time.

The bottom line is that the sort is really still a Quicksort. Hoare's description of choosing the pivot element neither requires nor prohibits a media of medians selection:

The first step of the partition process is to choose a particular key value which is known to be within the range of the keys of the items in the segment which is to be sorted. A simple method of ensuring this is to choose the actual key value of one of the items in the segment. The chosen key value will be called the bound.

Of course, nearly everybody now calls it the "pivot" instead of the "bound", but this is mostly irrelevant. The method used to choose the pivot/bound is left open.

like image 85
Jerry Coffin Avatar answered Sep 29 '22 23:09

Jerry Coffin