Multiplication - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Multiplication

Description:

Multiplication. General Structure of Divide and Conquer ... multiplication. tables. Just need to know. how to double, halve, and add. Multiplication a la russe ... – PowerPoint PPT presentation

Number of Views:105
Avg rating:3.0/5.0
Slides: 22
Provided by: seanwa6
Category:

less

Transcript and Presenter's Notes

Title: Multiplication


1
Multiplication
  • Lecture 11 Multiplication
  • Performance Analysis of Fire-Protection Designs
    for Forest Fire Game
  • Multiplication
  • General Structure of Divide and Conquer
    Algorithms
  • Lecture 10 Introduction to Divide and Conquer
  • Binary Search
  • Compare to Linear Search
  • Best/Worst Case Analysis
  • More Recursion Relations
  • Change of Variables
  • Intro to Probability
  • What Does Average Mean?
  • Average Case Analysis
  • Bonus! Forest Fire Game

2
Forest Fire Game
  • What symmetry properties
  • result from having no
  • information about where
  • lightening strikes?
  • (uniform distribution)
  • Does the Sign from Heaven
  • possibility skew the symmetry?
  • How good is your design if
  • the game were changed and
  • lightening struck according to
  • an entirely different distribution
  • than you designed for?
  • Can you see a natural trade-off
  • between robustness and
  • optimality in design problems?
  • 5 points extra credit if you analyze
  • 3 designs. 5 more if you prove an
  • optimal design and analyze how
  • its optimality changes with another

Total of Trees 225 Cut in Design 30
Lost/Strike 0,48,49
3
Divide and Conquer
...
...
...
Solve the smaller pieces.
4
Classic Multiplication
American Style
English Style
5001 x 502 10002 0 25005 .
2510502
5001 x 502 25005 0 10002 2510502
get O(n2) for 2 n-digit numbers
5
Multiplication a la russe
981 1234 1234 490 2468 245 4936 4936 122 987
2 61 19744 19744 30 39488
15 78976 78976 7 157952 157952
3 315904 315904 1 631808 631808
1210554.
  • Dont need to know
  • multiplication
  • tables
  • Just need to know
  • how to double,
  • halve, and add

6
Multiplication a la russe
101 101 101 0 10100 110012
2510
1012 x2 1012 101 101 101 10 1010 0
1 10100 10100 110012 2510
7
Arabic Multiplication
8
Divide and Conquer
0502 5001
05 x 50 shift 4 2500000 05 x 01 shift 2
500 02 x 50 shift 2 10000 02 x 01 shift 0
2 2510502
get O(n2)
9
Divide and Conquer
0502 5001
05 x 50 shift 4 2500000 05 x 01 shift 2
500 02 x 50 shift 2 10000 02 x 01 shift 0
2 2510502
get O(n2)
10
Divide and conquer
0502 5001
5001 x 502 10002 0 2500500 2510502
05 x 50 shift 4 2500000 05 x 01 shift 2
500 02 x 50 shift 2 10000 02 x 01 shift 0
2 2510502
get O(n2)
11
Is It Faster?
12
Divide and Conquer
05 x 50 shift 4 2500000 05 x 01 shift 2
500 02 x 50 shift 2 10000 02 x 01 shift 0
2 2510502
x
w
wy104 wz102 xy102 xz100
0502 5001
y
z
wy104 (wz xy)102 xz100
r (w x)(y z) wy wz xy xz
13
Divide and Conquer
05 x 50 shift 4 2500000 05 x 01 shift 2
500 02 x 50 shift 2 10000 02 x 01 shift 0
2 2510502
x
w
wy104 wz102 xy102 xz100
0502 5001
y
z
wy104 (wz xy)102 xz100
r (w x)(y z) wy wz xy xz
14
It Can Be Faster!
15
Divide and Conquer
wy104 (wz xy)102 xz100
p wy q xz r (w x)(y z) wy wz xy
xz p104 (r-p-q)102 q h(n) cn2 time to
multiply n-length ints g(n) time to add
up stuff 3h(n/2) g(n) 3c(n/2)2 g(n)
3/4h(n)g(n)
16
Recursive Application
...
...
...
17
Recursive Application
Run Time t(n) 3t(n/2) dn
Can we solve this difference equation?
Linear, Constant-Coefficient Geometric Forcing
Term (Eigenfunction)
18
Recursive Application
Run Time t(n) 3t(n/2) dn
Can we solve this difference equation?
Linear, Constant-Coefficient Geometric Forcing
Term (Eigenfunction)
As n?infinity 3n dominates 2n, Regardless of the
coefficients c0, c1
19
Recursive Application
Run Time t(n) 3t(n/2) dn
  • Divide and Conquer dropped run time from cn2 to
    (c/4)n2
  • Still of order Q(n2)!
  • Recursively applying Divide and Conquer changes
  • run time fundamentally, from Q(n2) to
    Q(nlg3)Q(n1.585)!
  • Choosing how deep to Divide and Conquer before
  • deciding the problem is small enough (that it
    would be
  • more efficient to apply the classic
    approach) is important
  • The size of a small enough instance is called
    the
  • threshold it affects the magnitude of the
    hidden constants
  • on order of growth of the run-time

20
General Structure forDivide and Conquer
function DC (x) if x lt threshold then
return adhoc(x) decompose x into l smaller
instances x1, x2 xl for i ? 1 to l do yi
? DC(xi) recombine the yis to get a
solution y for x return y where adhoc(x)
is the basic subalgorithm for small instances l
the number of divisions at each level
21
General Structure forDivide and Conquer
  • When is Divide and Conquer faster?
  • Tail Recursion can be written iteratively.
  • Is the iterative implementation better?
  • When it distills hidden inefficiencies.
  • Saves on stack allocation
  • Saves time calling the function
  • Less elegant to some tastesrecursion can
  • sometimes be more natural, more readable,
  • more maintainable.
Write a Comment
User Comments (0)
About PowerShow.com