Median from a data stream

I recently came across an interesting question : “Find Median from Data Stream”

The problem allows one to think of multiple concepts:

[1] Run-time complexity of adding in number to the data structure v/s finding median from the data structure

[2] can we leverage some form of counting sort algo

[3] what kinds of data structures might be useful useful Р heaps, segment trees, AVL etc etc

[4] I sensed some parallels with the range-minimum query problem as well.




The run-times are not great, but then I was not using any libraries.I wonder what optimizations other folks are doing to improve runtime.