median of n numbers without using array

java

#1

java program to find median of n numbers without using array


#2

If language-specific libraries are not intended then:

If the numbers are already sorted as they arrive then a LinkedList and using the two pointers approach would find the median, else a balanced binary search tree could be built to find the median.


#3

In principle, if you are handling values one by one, you will need to retain at least the first half of the values (if you know the eventual count of values) to ensure that you do not discard the median.

By contrast you can calculate the mean of a stream of values continuously. without retaining any data value after updating the mean.