Mediane mentaince algorithm