implementation of quick select algorithm