27
Solutions Manual Introduction to Algorithms – A Creative Approach September 1, 2013 i

Solutions - testing

Embed Size (px)

DESCRIPTION

Some description

Citation preview

Page 1: Solutions - testing

Solutions ManualIntroduction to Algorithms – A Creative Approach

September 1, 2013

i

Page 2: Solutions - testing
Page 3: Solutions - testing

Preface

This is a Solutions Manual for Udi Manber’s Introduction to Algorithms – ACreative Approach, a reference book on many Algorithm Courses.

All the solutions were written by students, we can’t guarantee that 100%of the solutions are correct, but you are more than welcome to contribute.

iii

Page 4: Solutions - testing

Contents

Preface iii

Contents iv

1 Introduction 1

2 Mathematical Induction 3

3 Analysis of Algorithms 5

4 Data Structures 7

5 Design of Algorithms by Induction 9

6 Algorithms Involving Sequences and Sets 11

7 Graph Algorithms 13

8 Geometric Algorithms 15

9 Algebraic and Numeric Algorithms 17

10 Reductions 19

11 NP-Completeness 21

12 Parallel Algorithms 23

iv

Page 5: Solutions - testing

Chapter 1

Introduction

Exercises

1

Page 6: Solutions - testing
Page 7: Solutions - testing

Chapter 2

Mathematical Induction

Drill exercises

Creative exercises

3

Page 8: Solutions - testing
Page 9: Solutions - testing

Chapter 3

Analysis of Algorithms

Drill exercises

3.5

a. We have that f(n) = 100n + log n and g(n) = n + (log n)2. Then let

limn→∞

f(n)

g(n)= lim

n→∞

100n + log n

n + (log n)2

By L’Hôpital’s rule

limn→∞

100n + log n

n + (log n)2= lim

n→∞

100 + 1n

1 + 2 lognn

= 100

∴ f(n) = O(g(n)) (3.1)

Now, let

limn→∞

g(n)

f(n)= lim

n→∞

n + (log n)2

100n + log n

By L’Hôpital’s rule

limn→∞

n + (log n)2

100n + log n= lim

n→∞

1 + 2 lognn

100 + 1n

=1

100

∴ g(n) = O(f(n)) ⇔ f(n) = Ω(g(n)) (3.2)

From (3.1) and (3.2) we have that

f(n) = Θ(g(n))

b. We have that f(n) = logn and g(n) = logn2. Note that

g(n) = logn2 = 2 log n = 2f(n)

∴ f(n) = Θ(g(n))

5

Page 10: Solutions - testing

6 CHAPTER 3. ANALYSIS OF ALGORITHMS

c. We have that f(n) = n2

logn and g(n) = n(log n)2. Then let

limn→∞

f(n)

g(n)= lim

n→∞

n2

logn

n(log n)2= lim

n→∞

n

(log n)3

By L’Hôpital’s rule

limn→∞

n

(log n)3= lim

n→∞

n

3(log n)2= lim

n→∞

n

6 log n= lim

n→∞

n

6= ∞

∴ f(n) 6= O(g(n))

Now, let

limn→∞

g(n)

f(n)= lim

n→∞

n(log n)2

n2

logn

= limn→∞

(log n)3

n

By L’Hôpital’s rule

limn→∞

(log n)3

n= lim

n→∞

3(log n)2

n= lim

n→∞

6 log n

n= lim

n→∞

6

n= 0

∴ g(n) = O(f(n)) ⇔ f(n) = Ω(g(n))

Creative exercises

Page 11: Solutions - testing

Chapter 4

Data Structures

Drill exercises

Creative exercises

7

Page 12: Solutions - testing
Page 13: Solutions - testing

Chapter 5

Design of Algorithms byInduction

Drill exercises

Creative exercises

9

Page 14: Solutions - testing
Page 15: Solutions - testing

Chapter 6

Algorithms Involving Sequencesand Sets

Drill exercises

Creative exercises

11

Page 16: Solutions - testing
Page 17: Solutions - testing

Chapter 7

Graph Algorithms

Drill exercises

Creative exercises

13

Page 18: Solutions - testing
Page 19: Solutions - testing

Chapter 8

Geometric Algorithms

Drill exercises

Creative exercises

15

Page 20: Solutions - testing
Page 21: Solutions - testing

Chapter 9

Algebraic and NumericAlgorithms

Drill exercises

Creative exercises

17

Page 22: Solutions - testing
Page 23: Solutions - testing

Chapter 10

Reductions

Drill exercises

Creative exercises

19

Page 24: Solutions - testing
Page 25: Solutions - testing

Chapter 11

NP-Completeness

Drill exercises

Creative exercises

21

Page 26: Solutions - testing
Page 27: Solutions - testing

Chapter 12

Parallel Algorithms

Drill exercises

Creative exercises

23