If I already have a min heap built what is the fastest way I can find the median? Seems like it is redundant to use the 2 heap (max and min) solution.
Asked
Active
Viewed 248 times
0
-
What advantages does a min heap has when searching for a Median? – Dolev Feb 27 '17 at 15:02
-
Faster than removing the minimum `n / 2` times? That will be `O(n log n)`, and pretty fast in practice. – IVlad Feb 27 '17 at 15:13
-
Yes looking for something with O(n) time complexity – jsho Feb 27 '17 at 15:15
-
I am currently thinking the solution won't alter the heap – jsho Feb 27 '17 at 15:25
-
1Why not use an O(n) algorithm that doesn't require a heap? – IVlad Feb 27 '17 at 15:30
-
1@jsho You can use any k-select algorithms where k is the median. This will satisfy all your requirements. No need for min heap tough... – Dolev Feb 27 '17 at 18:51