· Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our...

141
6.2 Master Theorem Lemma 1 Let a 1,b 1 and > 0 denote constants. Consider the recurrence T (n) = aT n b + f (n) . Case 1. If f (n) =O(n log b (a)- ) then T (n) = Θ(n log b a ). Case 2. If f (n) = Θ(n log b (a) log k n) then T (n) = Θ(n log b a log k+1 n). Case 3. If f (n) = Ω(n log b (a)+ ) and for sufficiently large n af ( n b ) cf(n) for some constant c< 1 then T (n) = Θ(f (n)). Note that the cases do not cover all pos- sibilities. EADS © Ernst Mayr, Harald Räcke 50/604

Transcript of  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our...

Page 1:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

6.2 Master Theorem

Lemma 1

Let a ≥ 1, b ≥ 1 and ε > 0 denote constants. Consider the

recurrence

T(n) = aT(nb

)+ f(n) .

Case 1.

If f(n) = O(nlogb(a)−ε) then T(n) = Θ(nlogb a).

Case 2.

If f(n) = Θ(nlogb(a) logkn) then T(n) = Θ(nlogb a logk+1n).

Case 3.

If f(n) = Ω(nlogb(a)+ε) and for sufficiently large naf(nb ) ≤ cf(n) for some constant c < 1 then T(n) = Θ(f (n)).

Note that the cases do not cover all pos-sibilities.

EADS

© Ernst Mayr, Harald Räcke 50/604

Page 2:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

6.2 Master Theorem

We prove the Master Theorem for the case that n is of the form

b`, and we assume that the non-recursive case occurs for

problem size 1 and incurs cost 1.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 51/604

Page 3:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 4:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 5:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 6:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 7:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

xn

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 8:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 9:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 10:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 11:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

alogbn

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 12:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

The Recursion Tree

The running time of a recursive algorithm can be visualized by a

recursion tree:

x f(n)

af(nb )

a2f( nb2 )

alogbn

nlogba=

n

nb

nb

nb

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

nb2

11111111 1 1 1 1 1 1 1

a

aaa

a a a a a a a a a

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 52/604

Page 13:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

6.2 Master Theorem

This gives

T(n) = nlogb a +logb n−1∑i=0

aif(nbi

).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 53/604

Page 14:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 15:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 16:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 17:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 18:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 19:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 20:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 21:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 22:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 23:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 24:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 25:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 1. Now suppose that f(n) ≤ cnlogb a−ε.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a−ε

= cnlogb a−εlogb n−1∑i=0

(bε)i

= cnlogb a−ε(bε logb n − 1)/(bε − 1)

= cnlogb a−ε(nε − 1)/(bε − 1)

= cbε − 1

nlogb a(nε − 1)/(nε)

Hence,

T(n) ≤(

cbε − 1

)nlogb(a)

∑ki=0 qi = qk+1−1

q−1

b−i(logb a−ε) = bεi(blogb a)−i = bεia−i

⇒ T(n) = O(nlogb a).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 54/604

Page 26:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 27:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 28:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 29:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 30:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 31:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 32:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 33:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = O(nlogb a logb n) ⇒ T(n) = O(nlogb a logn).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 55/604

Page 34:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 35:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 36:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 37:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 38:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 39:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 40:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 41:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≥ cnlogb a.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≥ clogb n−1∑i=0

ai(nbi

)logb a

= cnlogb alogb n−1∑i=0

1

= cnlogb a logb n

Hence,

T(n) = Ω(nlogb a logb n) ⇒ T(n) = Ω(nlogb a logn).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 56/604

Page 42:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 43:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a

=logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 44:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 45:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 46:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 47:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 48:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 49:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 50:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 51:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 52:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 2. Now suppose that f(n) ≤ cnlogb a(logb(n))k.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

≤ clogb n−1∑i=0

ai(nbi

)logb a·(

logb

(nbi

))k

= cnlogb a`−1∑i=0

(logb

(b`

bi

))k

= cnlogb a`−1∑i=0

(` − i)k

= cnlogb a∑i=1

ik

≈ cknlogb a`k+1

n = b` ⇒ ` = logb n

∑i=1

ik ≈ 1k`k+1

⇒ T(n) = O(nlogb a logk+1n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 57/604

Page 53:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 54:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 55:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 56:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 57:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 58:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 59:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 60:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Case 3. Now suppose that f(n) ≥ dnlogb a+ε, and that for

sufficiently large n: af(n/b) ≤ cf(n), for c < 1.

From this we get aif(n/bi) ≤ cif(n), where we assume that

n/bi−1 ≥ n0 is still sufficiently large.

T(n)−nlogb a =logb n−1∑i=0

aif(nbi

)

=logb n−1∑i=0

cif(n)+O(nlogb a)

≤ 11− c f(n)+O(n

logb a)

Hence,

T(n) ≤ O(f (n))

q < 1 :∑ni=0 qi = 1−qn+1

1−q ≤ 11−q

⇒ T(n) = Θ(f (n)).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 58/604

Page 61:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 62:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 63:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 64:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 65:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0

001001101

1

11011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 66:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0

001001101

1

11011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 67:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00

01001101

11

1011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 68:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00

01001101

11

1011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 69:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000

1001101

111

011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 70:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000

1001101

111

011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 71:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001

001101

1110

11001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 72:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001

001101

1110

11001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 73:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010

01101

11101

1001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 74:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010

01101

11101

1001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 75:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100

1101

111011

001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 76:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100

1101

111011

001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 77:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001

101

1110110

01

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 78:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001

101

1110110

01

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 79:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010011

01

11101100

1

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 80:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

00010011

01

11101100

1

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 81:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100110

1

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 82:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

000100110

1

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 83:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 84:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose we want to multiply two n-bit Integers, but our registers

can only perform operations on integers of constant size.

For this we first need to be able to add two integers A and B:

101011011 A

110010001 B

0001001101

111011001

This gives that two n-bit integers can be added in time O(n).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 59/604

Page 85:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 86:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 87:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 88:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 89:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 90:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

0

10001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 91:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 92:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 93:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

00

00000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 94:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 95:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 96:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

000

10001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 97:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 98:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 99:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 100:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 101:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).

ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 102:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Suppose that we want to multiply an n-bit integer A and an

m-bit integer B (m ≤ n).

1101×10001

10001

010001

0000000

00010001

11011101

Time requirement:

ñ Computing intermediate results: O(nm).ñ Adding m numbers of length ≤ 2n:

O((m+n)m) = O(nm).EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 60/604

Page 103:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB × . . .. . . . . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 104:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB ×

. . .. . . . . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 105:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

× . . .. . .

. . . . . .. . . . . .

a0anb0bn

an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 106:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . .

. . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 107:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 108:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 109:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

A recursive approach:

Suppose that integers A and B are of length n = 2k, for some k.

AB

×

. . .. . . . . . . . .. . . . . . a0anb0bn an2−1an

2bn

2−1bn2

B0B1 A0A1

Then it holds that

A = A1 · 2n2 +A0 and B = B1 · 2

n2 + B0

Hence,

A · B = A1B1 · 2n + (A1B0 +A0B1) · 2n2 +A0 · B0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 61/604

Page 110:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 111:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 112:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 113:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 114:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 115:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 116:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 117:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 118:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 119:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Algorithm 3 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z1 ←mult(A1, B0)+mult(A0, B1)7: Z0 ←mult(A0, B0)8: return Z2 · 2n + Z1 · 2

n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )2T(n2 )+O(n)T(n2 )O(n)

We get the following recurrence:

T(n) = 4T(n

2

)+O(n) .

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 62/604

Page 120:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

⇒ Not better then the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 63/604

Page 121:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

⇒ Not better then the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 63/604

Page 122:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

⇒ Not better then the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 63/604

Page 123:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

In our case a = 4, b = 2, and f(n) = Θ(n). Hence, we are in

Case 1, since n = O(n2−ε) = O(nlogb a−ε).

We get a running time of O(n2) for our algorithm.

⇒ Not better then the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 63/604

Page 124:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 125:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 126:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 127:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 128:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,

Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 129:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 130:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 131:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 132:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 133:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 134:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 135:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 136:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 137:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We can use the following identity to compute Z1:

Z1 = A1B0 +A0B1

= (A0 +A1) · (B0 + B1)−A1B1 −A0B0

= Z2︷ ︸︸ ︷A1B1

= Z0︷ ︸︸ ︷A0B0

Hence,Algorithm 4 mult(A, B)1: if |A| = |B| = 1 then

2: return a0 · b0

3: split A into A0 and A1

4: split B into B0 and B1

5: Z2 ←mult(A1, B1)6: Z0 ←mult(A0, B0)7: Z1 ←mult(A0+A1, B0+B1)−Z2−Z0

8: return Z2 · 2n + Z1 · 2n2 + Z0

O(1)O(1)O(n)O(n)T(n2 )T(n2 )T(n2 )+O(n)O(n)

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 64/604

Page 138:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 65/604

Page 139:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 65/604

Page 140:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 65/604

Page 141:  · Example: Multiplying Two Integers Suppose we want to multiply two n-bit Integers, but our registers can only perform operations on integers of constant size. For this we first

Example: Multiplying Two Integers

We get the following recurrence:

T(n) = 3T(n

2

)+O(n) .

Master Theorem: Recurrence: T[n] = aT(nb )+ f(n).ñ Case 1: f(n) = O(nlogb a−ε) T(n) = Θ(nlogb a)ñ Case 2: f(n) = Θ(nlogb a logkn) T(n) = Θ(nlogb a logk+1n)ñ Case 3: f(n) = Ω(nlogb a+ε) T(n) = Θ(f (n))

Again we are in Case 1. We get a running time of

Θ(nlog2 3) ≈ Θ(n1.59).

A huge improvement over the “school method”.

EADS 6.2 Master Theorem

© Ernst Mayr, Harald Räcke 65/604