added sorted median algorithm