add prototype partition function and implement median in terms of it

partition uses quickselect which has average linear complexity
improves performance of median which was using sort with linearithmic
complexity