2012 03 30 Algorithm Paradigms
2012 03 30 Algorithm Paradigms
Carlos Moreno
cmoreno @ uwaterloo.ca
EIT-4103
https://ece.uwaterloo.ca/~cmoreno/ece250
Divide-and-conquer
Greedy algorithms
Backtracking algorithms
Dynamic programming
Divide-and-conquer
Greedy algorithms
Backtracking algorithms
Dynamic programming
Divide-and-conquer:
Divide-and-conquer:
Key detail:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
Divide-and-conquer:
A= A H 2 + A L
n/2
B= B H 2 +B L
A= A H 2 + A L
n/2
B= B H 2 +B L
Thus:
n
A B = A H B H 2 + ( A H B L+ A L B H )2
n/ 2
+ AL B L
D1
D0
We notice that:
( A H + A L )( B H +B L ) = AH B H + A L B L + A H B L + A L B H
D1
D0
We notice that:
( A H + A L )( B H +B L ) = AH B H + A L B L + A H B L + A L B H
The left term involves one multiplication of half-size
operands, plus two additions, and the result is the
term D1 with two additional terms but these
additional terms are D0 and D2, which can be
reused, since they need to be computed anyway!
D0 = AL B L
D2 = AH + BH
D 1 = ( A H + A L ) ( B H +B L ) D 0 D 2
n/2
AB = D 2 2 + D 1 2 + D 0
D1
D2
D0
2n
Divide-and-conquer:
Divide-and-conquer:
Two approaches:
Top to bottom
Two approaches:
Top to bottom
Bottom to top
Summary
Divide-and-conquer
Greedy algorithms
Backtracking algorithms
Dynamic programming