
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Fundamental Algorithms; Subject: Computer Science; University: Wellesley College; Term: Spring 2009;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Computer Science 231 Spring 2009 Due: Friday, March 13 Reading. CLRS Chapters 8, 9, pages 165 -- 195 CLR Chapters 9, 10, pages 172 -- 194 CLRS Exercise 8.1-1. What is the smallest possible depth of a leaf in a decision tree for a comparison sort under the assumption that all elements are distinct? CLRS Exercise 8.1-4. You are given a sequence of n elements to sort. The input sequence consists of n/k subsequences, each containing k elements. The elements in a given subsequence are all smaller than the elements in the succeeding subsequence and larger than the elements in the preceding subsequence. Thus, all that is needed to sort the whole sequence of length n is to sort the k elements in each of the n/k subsequences. Show an Ω( n lg k ) lower bound on the number of comparisons needed to solve this variant of the sorting problem. ( Hint: It is not rigorous to simply combine the lower bounds for the individual subsequences.) CLRS Exercise 8.2-4. Describe an algorithm that, given n integers in the range 0 to k , preprocesses its input and then answers any query about how many of the n integers fall into a range [ a .. b ] in O (1) time. Your algorithm should use Θ( n + k ) preprocessing time. CLRS Exercise 8.3-5. Show how to sort n integers in the range 0 to n^2 - 1 in O( n ) time. CLRS Exercise 9.1-1. Show that the second smallest of n elements can be found with n + lg n - 2 comparisons in the worst cast. Hint: Build a "tournament tree" over the elements in which each node has a winner (smaller element) and a loser (larger element). Be careful that your algorithm accounts for all comparisons performed. CLRS Exercise 9.3-7. Describe an O(n) - time algorithm that, given a set S of n distinct numbers and a positive integer k ≤ n , determines the k numbers in S that are closest to the median of S.