Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Suppose you have an array A of n items, and you want to nd the k items in A closest to the median of A.

Suppose you have an array A of n items, and you want to find the k items in A closest to the median of A. For example, if A contains the 9 values {7, 14, 10, 12, 2, 11, 29, 3, 4} and k = 5, then the answer would be the values {7, 14, 10, 12, 11}, since the median is 10 and these are the five values in A closest to the value 10. Give an algorithm to solve this problem in O(n) time, and explain why your algorithm runs in O(n) time. You may use the selection algorithms discussed in the book and the notes as subroutines of your solution. (Hint: you may want to call the selection algorithm more than once.)

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question