exer3 - However, the only way you can access these values...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPT 307 — Data Structures and Algorithms Exercises on Median and Order Statistics. Due: Thursday, October 15th (at the beginning of the class) Reminder: the work you submit must be your own. Any collaboration and consulting outside resourses must be explicitely mentioned on your submission. 1. Show that the second smallest of n elements can be found with n + c log n C - 2 comparisons in the worst case. 2. Suppose that you have a “black box” worst-case linear time median subrouting. Give a simple, linear time algorithm that solves the selection problem for an arbitrary order statistics. 3. You are interested in analyzing some hard-to-obtain data from two separate databases. Each database contains n numerical values so there are 2 n values total and you may assume that no two values are the same. You would like to determine the median of this set of 2 n values, which we will deFne here to be the n -th smallest value.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

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 k-th 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 ) worst-case time using sorting. (b) Show how to compute the weighted median in ( n ) worst-case time using a linear time median algorithm such as Select. 1...
View Full Document

Ask a homework question - tutors are online