use partial sort to get the median of an array