Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

Students also viewed these Databases questions

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago