I tried to figure out where the “5” comes from the Median of Medians algorithm , but I can't seem to find a simple description of how it comes about and why it is optimal.
For example, why not say 7 is a viable option?
The only advantage I can see for 5 is that it has 2 elements on each side of the middle, making sorting by 5 elements a simple case of no more than three swaps.
5 , , O (n). 7 , .
: 5, :
T (n) ≤ T (n/5) + T (7n/10) + O (n)
O (n), .
3,
T (n) ≥ T (n/3) + T (2n/3) + O (n)
& Omega; (n log n).
7
T (n) ≤ T (n/7) + T (5n/7) + O (n)
O (n), . big-O , 5, n/7 7 , n/5 5. , .
, !