def _randomizedSelect(array, begin, end, i):
 if (begin == end):
  return array[begin]
 q = _randomizedPartition(array, begin, end)
 k = ((q - begin) + 1)
 if (i < k):
  return _randomizedSelect(array, begin, q, i)
 else:
  return _randomizedSelect(array, (q + 1), end, (i - k))

def _randomizedSelect ( array , begin , end , i ) : if ( begin == end ) : return array [ begin ] q = _randomizedPartition ( array , begin , end ) k = ( ( q - begin ) + 1 ) if ( i < k ) : return _randomizedSelect ( array , begin , q , i ) else : return _randomizedSelect ( array , ( q + 1 ) , end , ( i - k ) )
allows to select the ith smallest element from array without sorting it .