0

Image that explains the first algorithm

Generalized median-of-medians for sublist of size a

From this algorithm, we can see than in order to get linear running time for the algorithm, the constant has to be bigger than 4. However, I wondered what would happen if I divided into n/8 sublists and chose the 4th biggest number of each sublist as the median.

I expected the running time to be linear, since 8 > 4 however when I calculated the running time, I found O(nlogn). Calculating for sublist of size 8

Can someone please tell me if what I did is wrong, and explain to me why the sublist's size should always be odd?

juimdpp
  • 37
  • 1
  • 4
  • As for your last point, the [Wiki page on Median of medians](https://en.wikipedia.org/wiki/Median_of_medians) states that `Firstly, computing median of an odd list is faster and simpler; while one could use an even list, this requires taking the average of the two middle elements, which is slower than simply selecting the single exact middle element.` – 500 - Internal Server Error Apr 16 '20 at 09:21
  • You got the recurrence relation wrong. The algorithm doesn't recurse on both halves. T(5n/16) part should be T(n/8), representing the recursive quickselect on the medians. – Matt Timmermans Apr 16 '20 at 12:31

0 Answers0