History of ClassS04CS141/Notes 04 09

ClassS04CS141 | recent changes | Preferences


Revision 15 . . May 4, 2004 7:42 pm by Neal
Revision 14 . . April 12, 2004 3:56 pm by Neal
  

Difference (from prior major revision) (no other diffs)

Removed: 1d0

Recurrence relations, continued




Changed: 3,84c2
Try these:

# T(n) = 2 T(n/3) + n
# T(n) = 3 T(n/3) + n
# T(n) = 4 T(n/3) + n

1. recurrence tree is a complete binary tree of depth log3 n. The Ith level from the top has 2i nodes, each with work n/3i.

Total work is
: n[ 1 + (2/3) + (2/3)2 + ... + (2/3)log3 n]
which is O(n).

2. same as above but each node has 3 children, so the Ith level from the top has 3i nodes.

Total work is
: n[ 1 + (3/3) + (3/3)2 + ... + (3/3)log3 n]
which is O(n log n).

3. now each node has 4 children, so total work is
: n[ 1 + (4/3) + (4/3)2 + ... + (4/3)log3 n]
which is O(n (4/3)log3 n) = O(n1+log3 4/3) = O(n1.26...) .

Oh yeah? Try these!

# T(n) = 8 T(n/3) + n2
# T(n) = 9 T(n/3) + n2
# T(n) = 10 T(n/3) + n2

1. recurrence tree is of depth log3 n. Each node has 8 children.
The Ith level from the top has 8i nodes, each with work (n/3i)2 = n2 / 9i .

Total work is
: n2[ 1 + (8/9) + (8/9)2 + ... + (8/9)log3 n]
which is O(n2).

2.
Total work is
: n2[ 1 + (9/9) + (9/9)2 + ... + (9/9)log3 n]
which is O(n2 log n).

3.
Total work is
: n2[ 1 + (10/9) + (10/9)2 + ... + (10/9)log3 n]
which is O(n2 (10/9)log3 n) = O(n2.095...).

Oh YEAH?! TRY THIS:




# T(n) = 1.5 T(n/3.1) + n^{0.5}.

No recursion tree!?

Try repeated substitution.

After substitutions, get (1.5)i T(n / 3.1i) + (1.5)i-1 [n/3.1i-1]0.5 + ... .

Total work is
: n0.5[ 1 + (1.5/3.10.5) + (1.5/3.10.5)2 + ... + (1.5/3.10.5){log1.5 n}]

Since 1.5 < 3.10.5, this is O(n0.5).

ok, what about this one?




# T(n) = T(n/3) + T(n/2) + n, T(1) = 1.

Can make a recursion tree for this. Every node has two children, but depth is uneven, and work is not the same for each node on a level.
Try guessing, then prove by induction.

Guess that T(n) ≤ 10 n. Attempt proof by induction:

: Base case: T(1) ≤ 10 . (true)
: Inductive step: T(n) = T(n/3) + T(n/2) + n ≤ 10(n/3) + 10(n/2) + n = (10/3+10/2 + 1) n = 9.33.. n ≤ 10 n. (verified)

What is the best constant that would work?

Guess that T(n) ≤ c n. Attempt proof by induction:

: Base case: T(1) ≤ c . (need c ≥ 1 )
: Inductive step: T(n) = T(n/3) + T(n/2) + n ≤ c(n/3) + c(n/2) + n = (c(1/3+1/2) + 1) n ≤ c n ?

Need c(1/3+1/2)+1 ≤ c . True iff c ≥ 6 .

Conclude T(n) ≤ 6 n .
Continued with solving RecurrenceRelations .

ClassS04CS141 | recent changes | Preferences
Search: