Sunday, May 23, 2010

Top k elements in an array

Find top-k element in an integer array of size n.

1 comment:

  1. 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.

    ReplyDelete