Unformatted text preview: However, the only way you can access these values is through queries to the databases. In a single query, you can specify a value k to one of the two databases, and the chosen database will return kth smallest value that it contains. Since queries are expensive, you would like to compute the median using as few queries as possible. Give an algorithm that Fnds the median using at most O (log n ) queries. 4. ±or n distinct elements x 1 ,x 2 ,... ,x n with positive weights w 1 ,w 2 ,... ,w n such that ∑ n i =1 w i = 1, the weighted (lower) median is the element x k satisfying s x i <x k w i < 1 2 and s x i >x k w i ≤ 1 2 . (a) Show how to compute the median of n elements in O ( n log n ) worstcase time using sorting. (b) Show how to compute the weighted median in Θ( n ) worstcase time using a linear time median algorithm such as Select. 1...
View
Full
Document
This note was uploaded on 11/19/2009 for the course CS CMPT 307 taught by Professor A.bulatov during the Fall '09 term at Simon Fraser.
 Fall '09
 A.BULATOV
 Algorithms, Data Structures

Click to edit the document details