15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

c○: Michael Kohlhase 249<br />

The analysis for the cost is much more complex, we also have to solve a recursive equation, but a<br />

more difficult one. Instead of just guessing the correct closed form, we will use the opportunity to<br />

show a more general technique: using Master’s theorem for recursive equations. There are many<br />

similar theorems which can be used in situations like these, going into them or proving Master’s<br />

theorem would be beyond the scope of the course.<br />

The Cost of CSA<br />

C(CSA n ) = 3C(CSA n/2 ) + C(MUX n/2+1 ).<br />

Problem: How to solve this recursive equation?<br />

Solution: Guess a closed formula, prove by induction. (if we are lucky)<br />

Solution2: Use a general tool for solving recursive equations.<br />

Theorem 424 (Master’s Theorem for Recursive Equations) Given the recursively<br />

defined function f : N → R, such that f(1) = c ∈ R and f(b k ) = af(b k−1 ) + g(b k ) for some<br />

a ∈ R, 1 ≤ a, k ∈ N, and g : N → R, then f(b k ) = ca k + k−1<br />

i=0 ai g(b k−i )<br />

We have C(CSA n ) = 3C(CSA n/2 ) + C(MUX n/2+1 ) = 3C(CSA n/2 ) + 3(n/2 + 1) + 1 = 3C(CSA n/2 ) + 3<br />

2n + 4<br />

So, C(CSA n ) is a function that can be handled via Master’s theorem with a = 3, b = 2,<br />

n = b k , g(n) = 3/2n + 4, and c = C(f 1 CSA ) = C(FA1 ) = 5<br />

thus C(CSA n ) = 5 · 3log2 (n) + log2 (n)−1<br />

i=0 3i · 3<br />

2n · 2−i + 4<br />

Note: a log 2 (n) = 2 log 2 (a)log 2 (n) = 2 log 2 (a)·log 2 (n) = 2 log 2 (n)log 2 (a) = n log 2 (a)<br />

<br />

C(CSA n ) = 5 · 3 log2 (n) log2 (n)−1<br />

+<br />

<br />

i=0<br />

= 5n log2 (3) log2 (n)<br />

+<br />

i=1<br />

3 i · 3<br />

2 n · 2−i + 4<br />

n 3 i<br />

n + 4<br />

2<br />

= 5n log2 (3) log2 (n) i 3<br />

+ n · + 4log2 (n)<br />

2<br />

i=1<br />

= 5n log2 (3) + 2n · 3 log2 (n)+1<br />

− 1 + 4log<br />

2<br />

2(n)<br />

= 5n log 2 (3) + 3n · n log 2 ( 3 2 ) − 2n + 4log 2 (n)<br />

= 8n log 2 (3) − 2n + 4log 2 (n) ∈ O(n log 2 (3) )<br />

Theorem 425 The cost and the depth of the conditional sum adder are in the following<br />

complexity classes:<br />

C(CSA n ) ∈ O(n log 2 (3) ) dp(CSA n ) ∈ O(log 2(n))<br />

Compare with: C(CCA n ) ∈ O(n) dp(CCA n ) ∈ O(n)<br />

138

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!