Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to calculate median of a list of numbers better than O(n log n)?

I know that it is possible to calculate the mean of a list of numbers in O(n). But what about the median? Is there any better algorithm than sort (O(n log n)) and lookup middle element (or mean of two middle elements if an even number of items in list)?

like image 801
Kip Avatar asked Aug 21 '09 12:08

Kip


1 Answers

Yes. You can do it (deterministically) in O(n).

like image 172
Tyler McHenry Avatar answered Nov 15 '22 21:11

Tyler McHenry