How to calculate median of a Map<Int,Int>?
- by Chris
For a map where the key represents a number of a sequence and the value the count how often this number appeared in the squence, how would an implementation of an algorithm in java look like to calculate the median?
For example:
1,1,2,2,2,2,3,3,3,4,5,6,6,6,7,7
in a map:
Map<Int,Int> map = ...
map.put(1,2)
map.put(2,4)
map.put(3,3)
map.put(4,1)
map.put(5,1)
map.put(6,3)
map.put(7,2)
double median = calculateMedian(map);
print(median);
would result in:
> print(median);
3
>
So what i am looking for is a java implementation of calculateMedian.