some thought. Using selection algorithm, find the kth largest element in the array. That takes linear amount of time. Then partition the array around this value k (the way we do in quick sort). This again is done in linear amount of time. Return all the elements on the right of k.
some thought.
ReplyDeleteUsing selection algorithm, find the kth largest element in the array. That takes linear amount of time. Then partition the array around this value k (the way we do in quick sort). This again is done in linear amount of time.
Return all the elements on the right of k.