2
Problems for Chapter 4 107 Problems 4-1 Recurrence examples Give asymptotic upper and lower bounds for T .n/ in each of the following recur- rences. Assume that T .n/ is constant for n 2. Make your bounds as tight as possible, and justify your answers. a. T .n/ D 2T .n=2/ C n 4 . b. T .n/ D T .7n=10/ C n. c. T .n/ D 16T .n=4/ C n 2 . d. T .n/ D 7T .n=3/ C n 2 . e. T .n/ D 7T .n=2/ C n 2 . f. T .n/ D 2T .n=4/ C p n. g. T .n/ D T .n 2/ C n 2 . 4-2 Parameter-passing costs Throughout this book, we assume that parameter passing during procedure calls takes constant time, even if an N -element array is being passed. This assumption is valid in most systems because a pointer to the array is passed, not the array itself. This problem examines the implications of three parameter-passing strategies: 1. An array is passed by pointer. Time D ‚.1/. 2. An array is passed by copying. Time D ‚.N /, where N is the size of the array. 3. An array is passed by copying only the subrange that might be accessed by the called procedure. Time D ‚.q p C 1/ if the subarray AŒp : : qŁ is passed. a. Consider the recursive binary search algorithm for finding a number in a sorted array (see Exercise 2.3-5). Give recurrences for the worst-case running times of binary search when arrays are passed using each of the three methods above, and give good upper bounds on the solutions of the recurrences. Let N be the size of the original problem and n be the size of a subproblem. b. Redo part (a) for the MERGE-SORT algorithm from Section 2.3.1.

clrs-recorrencias

  • Upload
    luiz

  • View
    31

  • Download
    2

Embed Size (px)

DESCRIPTION

arquivo pdf

Citation preview

Problems for Chapter 4 107

Problems

4-1 Recurrence examplesGive asymptotic upper and lower bounds for T .n/ in each of the following recur-rences. Assume that T .n/ is constant for n � 2. Make your bounds as tight aspossible, and justify your answers.

a. T .n/ D 2T .n=2/C n4.

b. T .n/ D T .7n=10/C n.

c. T .n/ D 16T .n=4/C n2.

d. T .n/ D 7T .n=3/C n2.

e. T .n/ D 7T .n=2/C n2.

f. T .n/ D 2T .n=4/Cpn.

g. T .n/ D T .n � 2/C n2.

4-2 Parameter-passing costsThroughout this book, we assume that parameter passing during procedure callstakes constant time, even if an N -element array is being passed. This assumptionis valid in most systems because a pointer to the array is passed, not the array itself.This problem examines the implications of three parameter-passing strategies:

1. An array is passed by pointer. Time D ‚.1/.

2. An array is passed by copying. Time D ‚.N /, where N is the size of the array.

3. An array is passed by copying only the subrange that might be accessed by thecalled procedure. Time D ‚.q � p C 1/ if the subarray AŒp : : q� is passed.

a. Consider the recursive binary search algorithm for finding a number in a sortedarray (see Exercise 2.3-5). Give recurrences for the worst-case running timesof binary search when arrays are passed using each of the three methods above,and give good upper bounds on the solutions of the recurrences. Let N be thesize of the original problem and n be the size of a subproblem.

b. Redo part (a) for the MERGE-SORT algorithm from Section 2.3.1.

108 Chapter 4 Divide-and-Conquer

4-3 More recurrence examplesGive asymptotic upper and lower bounds for T .n/ in each of the following recur-rences. Assume that T .n/ is constant for sufficiently small n. Make your boundsas tight as possible, and justify your answers.

a. T .n/ D 4T .n=3/C n lg n.

b. T .n/ D 3T .n=3/C n= lg n.

c. T .n/ D 4T .n=2/C n2p

n.

d. T .n/ D 3T .n=3 � 2/C n=2.

e. T .n/ D 2T .n=2/C n= lg n.

f. T .n/ D T .n=2/C T .n=4/C T .n=8/C n.

g. T .n/ D T .n � 1/C 1=n.

h. T .n/ D T .n � 1/C lg n.

i. T .n/ D T .n � 2/C 1= lg n.

j. T .n/ D pnT .p

n/C n.

4-4 Fibonacci numbersThis problem develops properties of the Fibonacci numbers, which are definedby recurrence (3.22). We shall use the technique of generating functions to solvethe Fibonacci recurrence. Define the generating function (or formal power se-ries) F as

F .´/ D1X

iD0

Fi´i

D 0C ´C ´2 C 2´3 C 3´4 C 5´5 C 8´6 C 13´7 C 21´8 C � � � ;

where Fi is the i th Fibonacci number.

a. Show that F .´/ D ´C ´F .´/C ´2F .´/.