CSCE 411 Lecture 6

From Notes
Jump to navigation Jump to search
Lecture Slides

« previous | Friday, September 7, 2012 | next »


Master Theorem

T(n)=aT(nb)+f(n)

We assume a1, b>1, and f(n) eventually positive

  1. f(n)=O(nlogbaϵ)T(n)=Θ(nlogba)
  2. f(n)=Θ(nlogba)T(n)=Θ(nlogbalogn)
  3. f(n)=Ω(nlogba+ϵ)T(n)=Θ(f(n))

Note: For case 3, f(n) must be regular

Matrix Multiplication

Classic algorithm

AB=(j=1naijbjk) for 1(i,j,k)n

for i from 1 to n do:

 for j from 1 to k do:
   for t from 1 to m do:
   end for
 end for

end for

Approx Θ(n3)

Divide and Conquer

[A0A1A2A3]×[B0B1B2B3]=[A0×B0+A1×B2A0×B1+A1×B3A2×B0+A3×B2A2×B1+A3×B3]

Divide batrices A and B into four smaller matrices:

  • 8 matrix multiplications on submatrices of A and B
  • Θ(n2) scalar additions

Running Time

  • T(n)=8T(n2)+Θn2
  • T(2)=Θ(1)
  • T(n)Θ(n3) great, all that work for nothing.

Can we do fewer operations?

Strassen's Matrix

Just calculate 7 products and do a bunch of cheap additions

T(n)=7T(n2)+Θ(n2)O(n2.807)


Integer Multiplication

Elementary school algorithm 41×42=1010012×1010102=10101002+1010100002+101010000002=110101110102=172210

Multiplication of 2 n-bit numbers takes Ω(n2).

Kolmogrov (at one of his seminars) conjectured that we can't do better, but Karatsuba proved him wrong a week later.

Dividery and Conquery

Split x and y into two smaller parts: their most significant and least significant parts:

  • x=2n2A+B, where A and B are n/2-bit algorithms
  • x=2n2C+D, where C and D are n/2-bit algorithms
  • xy=2nAC+2n2BC+2n2AD+BD still T(n)=4T(n2)+Θ(n)=Θ(n2)

What if we multiply (A+B)(C+D)=AC+AD+BC+BD? Just correct the terms:

xy=(2n2n2)AC+2n2(A+B)(C+D)+(12n2)BD

This has only 3 multiplications, so T(n)=3(n2)+Θ(n)=Θ(nlog23)

Summary of Dividery and Conquery

  1. Split x into two parts A and B
  2. Split y into two parts C and D
  3. calculate AC, (A+B)(C+D), and BD
  4. shift each of the results by a certain amount and add all of those together