solu4 - 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 4 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 4.1 1. a. Write a pseudocode For a divide-and-conquer algorithm For fnding the position oF the largest element in an array oF n numbers. b. What will be your algorithm’s output For arrays with several elements oF the largest value? c. Set up and solve a recurrence relation For the number oF key com- parisons made by your algorithm. d. How does this algorithm compare with the brute-Force algorithm For this problem? 2. a. Write a pseudocode For a divide-and-conquer algorithm For fnding val- ues oF both the largest and smallest elements in an array oF n numbers. b. Set up and solve (For n =2 k ) a recurrence relation For the number oF key comparisons made by your algorithm. c. How does this algorithm compare with the brute-Force algorithm For this problem? 3. a. Write a pseudocode For a divide-and-conquer algorithm For the ex- ponentiation problem oF computing a n where a> 0 and n is a positive integer. b. Set up and solve a recurrence relation For the number oF multipli- cat ionsmadebyth isa lgor ithm . c. How does this algorithm compare with the brute-Force algorithm For this problem? 4. As mentioned in Chapter 2, logarithm bases are irrelevant in most contexts arising in analyzing an algorithm’s efficiency class. Is it true For both assertions oF the Master Theorem that include logarithms? 5. ±ind the order oF growth For solutions oF the Following recurrences. a. T ( n )=4 T ( n/ 2) + n, T (1) = 1 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
b. T ( n )=4 T ( n/ 2) + n 2 ,T (1) = 1 c. T ( n T ( n/ 2) + n 3 (1) = 1 6. Apply mergesort to sort the list E, X, A, M, P, L, E in alphabetical order. 7. Is mergesort a stable sorting algorithm? 8. a. Solve the recurrence relation for the number of key comparisons made by mergesort in the worst case. (You may assume that n =2 k . ) b. Set up a recurrence relation for the number of key comparisons made by mergesort on best-case inputs and solve it for n k . c. Set up a recurrence relation for the number of key moves made by the version of mergesort given in Section 4.1 . Does taking the number of key moves into account change the algorithm’s efficiency class? 9. Let A [0 ..n 1] be an array of n distinct real numbers. A pair ( A [ i ] ,A [ j ]) is said to be an inversion if these numbers are out of order, i.e., i<j but A [ i ] >A [ j ] . Design an O ( n log n ) algorithm for counting the number of inversions. 10. One can implement mergesort without a recursion by starting with merg- ing adjacent elements of a given array, then merging sorted pairs, and so on. Implement this bottom-up version of mergesort in the language of your choice.
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 / 44

solu4 - 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