solu6 - This le contains the exercises, hints, and...

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

View Full Document Right Arrow Icon
This fle contains the exercises, hints, and solutions For Chapter 6 oF the book ”Introduction to the Design and Analysis oF Algorithms,” 2nd edition, by A. Levitin. The problems that might be challenging For at least some students are marked by ± ; those that might be difficult For a majority oF students are marked by ² . Exercises 6.1 1. Recall that the median oF a list oF n numbers is defned as its ± n/ 2 ² smallest element. (The median is larger than one halF the elements and is smaller than the other halF.) Design a presorting-based algorithm For fnding the median and determine its efficiency class. 2. Consider the problem oF fnding the distance between the two closest num- bers in an array oF n numbers. (The distance between two numbers x and y is computed as | x y | .) a. Design a presorting-based algorithm For solving this problem and de- termine its efficiency class. b. Compare the efficiency oF this algorithm with that oF the brute-Force algorithm (see Problem 9 in Exercises 1.2). 3. Let A = { a 1 , ... ,a n } and B = { b 1 ,...,b m } be two sets oF numbers. Consider the problem oF fnding their intersection, i.e., the set C oF all the numbers that are in both A and B . a. Design a brute-Force algorithm For solving this problem and deter- mine its efficiency class. b. Design a presorting-based algorithm For solving this problem and de- termine its efficiency class. 4. Consider the problem oF fnding the smallest and largest elements in an array oF n numbers. a. Design a presorting-based algorithm For solving this problem and de- termine its efficiency class. b. Compare the efficiency oF the three algorithms: (i) the brute-Force algorithm, (ii) this presorting-based algorithm, and (iii) the divide-and- conquer algorithm (see Problem 2 in Exercises 4.1). 5. Show that the average-case efficiency oF one-time searching by the algo- rithm that consists oF the most efficient comparison-based sorting algo- rithm Followed by binary search is inFerior to the average-case efficiency oF sequential search. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
6. Estimate how many searches will be needed to justify time spend on pre- sorting an array of 10 3 elements if sorting is done by mergesort and search- ing is done by binary search. (You may assume that all searches are for elements known to be in the array.) What about an array of 10 6 elements? 7. To sort or not to sort? Design a reasonably efficient algorithm for solving each of the following problems and determine its efficiency class. a. You are given n telephone bills and m checks sent to pay the bills ( n m ) . Assuming that telephone numbers are written on the checks, Fnd out who failed to pay. (±or simplicity, you may also assume that only one check is written for a particular bill and that it covers the bill in full.) b. You have a Fle of n student records indicating each student’s num- ber, name, home address, and date of birth. ±ind out the number of students from each of the 50 U.S. states.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 54

solu6 - This le contains the exercises, hints, and...

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