Give an algorithm to solve this problem in o


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. 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 ?ve 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!!
Data Structure & Algorithms: Give an algorithm to solve this problem in o
Reference No:- TGS0144518

Expected delivery within 24 Hours