Median maintenance algorithm implemented