Suppose you have an array a of n items and you want to find


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

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Suppose you have an array a of n items and you want to find
Reference No:- TGS0144388

Expected delivery within 24 Hours