Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Data-Structures-And-Algorithms-Alfred-V-Aho

.pdf
Скачиваний:
122
Добавлен:
09.04.2015
Размер:
6.91 Mб
Скачать

Data Structures and Algorithms: CHAPTER 9: Algorithm Analysis Techniques

Solve the following recurrences, where T(1) = 1 and T(n) for n ³ 2 satisfies:

a. T(n) = 4T(n/3) + n

9.3

b. T(n) = 4T(n/3) + n2 c. T(n) = 9T(n/3) + n2

 

Give tight big-oh and big-omega bounds on T(n) defined by the

 

following recurrences. Assume T(1) = 1.

 

a. T(n) = T(n/2) + 1

9.4

b. T(n) = 2T(n/2) + logn

 

c. T(n) = 2T(n/2) + n

 

d. T(n) = 2T(n/2) + n2

Solve the following recurrences by guessing a solution and checking your answer.

a.

T(1)

= 2

*9.5

T(n)

= 2T(n-1) + 1 for n ³ 2

b. T(1)

= 1

 

T(n)

= 2T(n-1) + n for n ³ 2

9.6

Check your answers to Exercise 9.5 by solving the recurrences by repeated substitution.

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1209.htm (16 of 19) [1.7.2001 19:24:52]

Data Structures and Algorithms: CHAPTER 9: Algorithm Analysis Techniques

 

Generalize Exercise 9.6 by solving all recurrences of the form

9.7

T(1) = 1

 

T(n) = aT(n-1) + d(n)

for n ³ 1

 

 

in terms of a and d(n).

 

*9.8

Suppose in Exercise 9.7 that d(n) = cn for some constant c ³ 1. How

does the solution to T(n) depend on the relationship between a and c.

 

What is T(n)?

 

 

Solve for T(n):

 

**9.9

T(1) = 1

 

 

T(n) = Ö`nT(Ö`n) + n

for n ³ 2

Find closed form expressions for the following sums.

9.10

Show that the number of different orders in which to multiply a sequence of n matrices is given by the recurrence

*9.11

Show that . The T(n)'s are called Catalan numbers.

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1209.htm (17 of 19) [1.7.2001 19:24:52]

Data Structures and Algorithms: CHAPTER 9: Algorithm Analysis Techniques

Show that the number of comparisons required to sort n elements using mergesort is given by

T(1) = 0

T(n) = T([n/2]) + T([n/2]) + n - 1

**9.12

where [x] denotes the integer part of x and [x] denotes the smallest integer ³ x. Show that the solution to this recurrence is

T(n) = n[logn] - 2[logn] + 1

Show that the number of Boolean functions of n variables is given by the recurrence

9.13T(1) = 4

T(n) = (T(n - 1))2

Solve for T(n).

Show that the number of binary trees of height £ n is given by the recurrence

**9.14

T(1) = 1

 

 

T(n) = (T(n - 1))2 + 1

 

Show that T(n) = [k2n] for some constant k. What is the value of k?

Bibliographic Notes

Bentley, Haken, and Saxe [1978], Greene and Knuth [1983], Liu [1968], and Lueker [1980] contain additional material on the solution of recurrences. Aho and Sloane [1973] show that many nonlinear recurrences of the form T(n) = (T(n-1))2 + g(n) have a solution of the form T(n) = [k2n] where k is a constant, as in Exercise 9.14.

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1209.htm (18 of 19) [1.7.2001 19:24:52]

Data Structures and Algorithms: CHAPTER 9: Algorithm Analysis Techniques

† But don't hold out much hope for discovering a way to merge two sorted lists of n/2 elements in less than linear time; we couldn't even look at all the elements on the list in that case.

Table of Contents Go to Chapter 10

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/mf1209.htm (19 of 19) [1.7.2001 19:24:52]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_3.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_3.gif [1.7.2001 19:25:12]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_4.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_4.gif [1.7.2001 19:25:24]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_6.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_6.gif [1.7.2001 19:25:37]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_8.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_8.gif [1.7.2001 19:25:51]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_9.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_9.gif [1.7.2001 19:26:07]

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_12.gif

http://www.ourstillwaters.org/stillwaters/csteaching/DataStructuresAndAlgorithms/images/fig8_12.gif [1.7.2001 19:26:12]

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]