hw6 - EE608, Homework #6 8.2-4 Describe an algorithm that,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EE608, Homework #6 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 0(1) time. Your algorithm should use @(n + k) preprocessing time. 8.3-1 Using Figure 8.3 as a model, illustrate the operation of RADIX—SORT on the fol- lowing list of English words: COW, DOG, SEA, RUG, ROW, MOB, BOX, TAB, BAR, EAR, TAR, DIG, BIG, TEA, NOW, FOX. 8.3-3 Use induction to prove that radix sort works. Where does your proof need the assumption that the intermediate sort is stable? 8.3-4 Show how to sort )1 integers in the range 0 to 112 —~ 1 in 0(n) time. 8.4—2 What is the worst—case running time for the bucket—sort algorithm? What simple change to the algorithm preserves its linear expected running time and makes its worstacase running time 0 (11 lg n)? 8~3 Sorting variable-length items a. You are given an array of integers, where different integers may have different numbers of digits, but the total number of digits over all the integers in the array is n. Show how to sort the array in 0 (n) time. b. You are given an array of strings, where different strings may have different numbers of characters, but the total number of characters over all the strings is n. Show how to sort the strings in 0 (n) time. (Note that the desired order here is the standard alphabetical order; for example, a < ab < b.) 9.1-1 Show that the second smallest of n elements can be found with n + 1” lg 11] ~— 2 comparisons in the worst case. (Hint: Also find the smallest element.) 9.1«2 * Show that Bn/Zl ~ 2 comparisons are necessary in the worst case to find both the maxrmum and minimum of n numbers. (Hint: Consider how many numbers are potentially either the maximum or minimum, and investigate how a comparison affects these counts.) 93-] In the algorithm SELECT, the input elements are divided into groups of 5. Will the algorithm work in linear time if they are divided into groups of 7? Argue that SELECT does not run in linear time if groups of 3 are used. 9.34 * Suppose that an algorithm uses on in a set of n elements. Show that . ' . the n — i larger elements without performing any additional compari 1y comparisons to find the i th smallest element it can also find the i - 1 smaller elements and sons. 92 Weighted median For n distinct elements x1, x2, . . . , x,, with positive weights w1, w2, . . . , 21)” such that 217:1 w = 1, the weighted (lower) median is the element xk satisfying 1 w < — xi<xk 2 and 1 xi>xk 2' a. Argue that the median of x1, x2, . . . ,xn is the weighted median of the x,- with weights wi=1/n fori = 1, 2,...,n. b. Show how to compute the weighted median of n elements in 0(n lg n) worst— case time using sorting. c. Show how to compute the weighted median in @(n) worst—case time using a linear—time median algorithm such as SELECT from Section 9.3. The post-oflice location problem is defined as follows. We are given n points p1, p2, . . . , p” with associated weights wl, 1.02, . . . , wn. We wish to find a point p (not necessarily one of the input points) that minimizes the sum 21:1 w d (p, pi), where d(a, b) is the distance between points a and b. d. Argue that the weighted median is a best solution for the 1-dimensional post" office location problem, in which points are simply real numbers and the dis~ tance between points a and b is d(a, b) 2 la — bl. ‘e. ' - . . best. solution for the 2~dimen31onal post-office location problem, it: C e pomts are (X, 3’) Coordinate pairs and the distance between points a 2 (X1; yl) and b :: (152’ yz) is the Manhatt , ' m In — x2! + lyi — ya. ‘1” “WW given by do. b) —— ...
View Full Document

This note was uploaded on 07/10/2011 for the course STAT 695 taught by Professor Staff during the Spring '08 term at Purdue.

Page1 / 3

hw6 - EE608, Homework #6 8.2-4 Describe an algorithm that,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online