cse101_10_14_11

# cse101_10_14_11 - work T(n = 3(n/2 O(n = O(n log3 = O(n...

This preview shows pages 1–2. Sign up to view the full content.

Integer multiplication 1. Algorithms for multiplication a. Grade school method 36*10 36 10 18 20 9 40 4 80 2 160 1 320 Then cross off anything that starts with even number. Both O(n 2 ) to multiply n-bit numbers b. Divide and conquer X,y are n-bit numbers. Want to compute xy. X = X l x r = x l 2 n/2 + x r Y = y l 2 n/2 + y r Xy = (x l 2 n/2 + x r )(y l 2 n/2 + y r ) = x l y l 2 n + (x l y r + x r y l ) 2 n/2 + x r y r Idea: to multiply xy, n bits Recursively do the n/2-bit multiplications x l y l , x l ,y r , x r y l , x r y r Do a few left-shifts and additions Running time = T(n) = 4T(n/2) + O(n) c. A better divide and conquer To solve the n-bit problem xy, we only need to solve three n/2-bit problems x l y l x r y r (x l + x r )(y l +y r ) The third term we need, x l y r + x r y l , can be written x l y r + x r y l = (x l + x r )(y l +y r ) – x l y l - x r y r To solve n-bit problem xy, solve these three n/2-bit problems and do O(n) extra

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: work T(n) = 3(n/2) + O(n) = O(n log3 ) = O(n 1.59 ) Xy = x l y l 2 n + (x l y r + x rl )2 n/2 + x r y r d. Solve recurrences T(n) = 4(T(n/2) + cn = 4[4T(n/4) + cn/2] + cn = 16T(n/4) + 3cn = 4 k T(n/2 k ) + (2 k-1)cn T(n) = 3(n/2) + n = [3T(n/4)+n/2]+n = 9T(n/4)+n(1+3/2) T(n) = 3 k T(n/2 k ) + n(1+3/2+…+(3/2) k-1 ) Plug in k log 2 n T(n) = 3 logn T(1) + nO((3/2) logn ) T(n) = O(3 logn + n(3/2) logn ) 3 logn = (2 log3 ) logn = (2 logn ) log3 = n log3 (n) = O(n log3 ) = O(n 1.6 ) Our integer multiplication algorithm Log 2 n height Example: integer multiplication T(n) = 3T(n/2) + O(n) a = 3, b = 2, d = 1 e....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

cse101_10_14_11 - work T(n = 3(n/2 O(n = O(n log3 = O(n...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online