08 - Divide and conquer algorithms- Multiplying polynomials and integers (Karatsuba’s algori

08 - Divide and conquer algorithms- Multiplying polynomials and integers (Karatsuba’s algori

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
2/4/08 - Divide and conquer algorithms:. .. Lecture: Divide and conquer algorithms: Multiplying polynomials and integers (Karatsuba's algorithm) Reading: Chapter 5.1, 5.2, 5.5 Mergesort Binary search Quicksort Algebra + Geometry Polynomial multiplication (ax + b)(cx + d) = acx 2 + (ad + bc)x + bd 4 mult 1 add Karatsuba's Algorithm (1960) (a + b)(c + d) = ac + ad + bc + bd 1) Compute (a + b)(c + d) = p, ac = q, bd = r 2 add, 3 mult 2) Output the polynomial qx 2 + (p - q - r)x + r 2 subt 3 mult, 4 add/sub Suppose given polynomials A(x) and B(x) of degree n - 1 = 2m - 1 A(x) = a 0 + a 1 x + a 2 x 2 + . .. + a n-1 x n-1 B(x) = b 0 + b 1 x + . .. + b n-1 x n-1 Write A(x) = P 1 (x) + x m P 2 (x) deg P 1 , P 2 < m P 1 (x) = a 0 + . .. + a m-1 x m-1 x m P 2 (x) = x m (a m + a m+1 x + . .. + a 2m-1 x m-1 ) B(x) = Q 1 (x) + x m Q 2 (x) 9-1 9
Background image of page 1

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

View Full DocumentRight Arrow Icon
AB = P 1 Q 1 + x m (P
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Q 2 + P 2 Q 1 ) + x 2m (P 2 Q 2 ) Let F = (P 1 + P 2 )(Q 1 + Q 2 ) G = P 1 Q 2 H = P 2 Q 1 =&gt; AB = G + (F - G - H)x m + Hx 2m 3 poly m * poly m 2 poly m + poly m 2 poly n- poly n Let f(d) = running time to mult. 2 polynomials of degree d - 1. f(2m) = 3f(m) + 2m + 4m = 3f(m) + 6m m = 2 k 2 k-1 9-2 Basic Recursions: f(2n) = f(n) + O(1) -&gt; f = O(logn) f(2n) = 2f(n) + O(1) -&gt; f = O(n) f(2n) = f(n) + O(n) -&gt; f = O(n) f(2n) = 2f(n) + O(n) -&gt; f = O(nlogn) Integer Multiplication You can also use Karatsuba as a O(n 1.585 ) algorithm for multiplying n-bit ints A = 10110101 P 1 = 1001 Q 1 = 11 P 2 = 0101 To multiply n-bit integers, takes g(n) = 3g(|n/2|) + O(n) =&gt; g(n) = O(n 1.585 ) 9-3...
View Full Document

This note was uploaded on 10/02/2008 for the course CS 482 taught by Professor Kleinberg during the Spring '08 term at Cornell University (Engineering School).

Page1 / 3

08 - Divide and conquer algorithms- Multiplying polynomials and integers (Karatsuba&acirc;€™s algori

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online