2014-05-12 + HW

posted May 12, 2014, 9:40 AM by Samuel Konstantinovich   [ updated May 15, 2014, 4:54 AM ]
UPDATED
You are writing a RunningMedian class which is a container that has optimized methods to add/remove elements, and calculate the median. In addition to a default constructor that makes an empty container, It supports 3 methods:

void add(int value) 
    add an integer to the collection, should not be worse than O(logn) , duplicates are allowed.

double remove()  
    remove the median (or both medians) from the collection and return its value (or the average of two values), should not be worse than O(logn). Throws an IllegalStateException() when there are no values in the container.

double median()
    return the median of the collection. Should not be worse than O(1). Throws an IllegalStateException() when there are no values in the container.
Comments