I believe there’s a way to find the kth largest element in an unsorted array of length n in O(n). Or perhaps it’s ‘expected’ O(n) or something. How can we do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is called finding the k-th order statistic. There’s a very simple randomized algorithm (called quickselect) taking
O(n)average time,O(n^2)worst case time, and a pretty complicated non-randomized algorithm (called introselect) takingO(n)worst case time. There’s some info on Wikipedia, but it’s not very good.Everything you need is in these powerpoint slides. Just to extract the basic algorithm of theO(n)worst-case algorithm (introselect):It’s also very nicely detailed in the Introduction to Algorithms book by Cormen et al.