advanced design and analysis techniques - part 1 · 2012-11-06 · techniques -1 • this part...

21
Advanced Design and Analysis Techniques Part 1 15.1 and 15.2 1

Upload: others

Post on 05-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Advanced Design and Analysis

TechniquesTechniques

Part 1

15.1 and 15.2

1

Page 2: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

2

Page 3: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Techniques -1

• This part covers three important techniques

for the design and analysis of efficient

• algorithms:

– dynamic programming (Chapter 15),– dynamic programming (Chapter 15),

– greedy algorithms (Chapter 16),and

– amortized analysis (Chapter 17).

3

Page 4: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Techniques - 2

• Earlier parts have presented other widely

applicable techniques, such as

– divide-and-conquer,

– randomization, and– randomization, and

– the solution of recurrences.

4

Page 5: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Dynamic programming

• Dynamic programming typically applies tooptimization problems in which a set ofchoices must be made in order to arrive at anoptimal solution.

• Dynamic programming is effective when agiven subproblem may arise from more thanone partial set of choices; the key technique isto store the solution to each such subproblemin case it should reappear.

5

Page 6: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Greedy algorithms

• Like dynamic-programming algorithms, greedy

algorithms typically apply to optimization

problems in which a set of choices must be

made in order to arrive at an optimal solution.made in order to arrive at an optimal solution.

The idea of a greedy algorithm is to make each

choice in a locally optimal manner.

6

Page 7: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Dynamic programming -1

• Dynamic programming, like the divide-and-

conquer method, solves problems by

combining the solutions to subproblems.

• Divide and- conquer algorithms partition the• Divide and- conquer algorithms partition the

problem into independent subproblems, solve

the subproblems recursively, and then

combine their solutions to solve the original

problem.

7

Page 8: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Dynamic programming -2

• Dynamic programming is applicable when the

subproblems are not independent, that is,

when subproblems share subsubproblems.

• A dynamic-programming algorithm solves• A dynamic-programming algorithm solves

every subsubproblem just once and then

saves its answer in a table, thereby avoiding

the work of recomputing the answer every

time the subsubproblem is encountered.

8

Page 9: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Dynamic programming -2

• Dynamic programming is typically applied tooptimization problems. In such problemsthere can be many possible solutions. Eachsolution has a value, and we wish to find asolution with the optimal (minimum orsolution with the optimal (minimum ormaximum) value. We call such a solution an

optimal solution to the problem, as opposedto the optimal solution, since there may beseveral solutions that achieve the optimalvalue.

9

Page 10: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

The development of a dynamic-

programming algorithm

• The development of a dynamic-programmingalgorithm can be broken into a sequence of foursteps.

1. Characterize the structure of an optimalsolution.solution.

2. Recursively define the value of an optimalsolution.

3. Compute the value of an optimal solutionin a bottom-up fashion.

4. Construct an optimal solution fromcomputed information.

10

Page 11: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Assembly-line scheduling

11

Page 12: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 1: The structure of the fastest way through the factory

12

Page 13: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 2: A recursive solution

13

Page 14: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 3: Computing the fastest times

14

Page 15: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 4: Constructing the fastest way

through the factory

15

Page 16: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Matrix-chain multiplication

16

We can multiply two matrices A and B only if they are compatible: the number

of columns of A must equal the number of rows of B. If A is a p × q matrix and B

is a q × r matrix, the resulting matrix C is a p × r matrix

Page 17: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Counting the number of

parenthesizations

17

Page 18: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

• Step 1: The structure of an optimal

parenthesization

• Step 2: A recursive solution

• Step 3: Computing the optimal costs

18

Page 19: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 3: Computing the optimal costs

19

Page 20: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

20

Page 21: Advanced Design and Analysis Techniques - part 1 · 2012-11-06 · Techniques -1 • This part covers three important techniques forthe design and analysis ofefficient • algorithms:

Step 4: Constructing an optimal

solution

21