We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I would suggest initializing the size of your list otherwise you don't really have constant time list insertion.
Also I would change the class name since you implemented a sorted list solution rather than using heaps.
I prefer this type of solution where you just sort the list as you intake the numbers and then more easily compute the median. Compared to the heap solution, the coding is much simpler, yet the run-time and space usage remain asymptotically the same.
Heaps: Find the Running Median
You are viewing a single comment's thread. Return to all comments →
I would suggest initializing the size of your list otherwise you don't really have constant time list insertion.
Also I would change the class name since you implemented a sorted list solution rather than using heaps.
I prefer this type of solution where you just sort the list as you intake the numbers and then more easily compute the median. Compared to the heap solution, the coding is much simpler, yet the run-time and space usage remain asymptotically the same.
T: O(n log n) S: O(n)