0% found this document useful (0 votes)
113 views

CSCI 3110 Assignment 6 Solutions: n ≈ n nlogn=O n n − ϵ where ϵ = (log − log

This document provides solutions to several recurrence relations problems: 1. It uses the Master Theorem or other methods to solve six recurrence relations, explaining which case applies or why the Master Theorem does not apply. 2. It uses substitution or recursion trees to solve two recurrences, showing the steps to obtain the solutions. 3. It provides a justification for the solution to the bonus recurrence T(n) = 2T(n-1) + T(n-2) + 1 being exponential without proving it, finding the exponential base to be approximately 2.42.

Uploaded by

Ricardo Bruno
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

CSCI 3110 Assignment 6 Solutions: n ≈ n nlogn=O n n − ϵ where ϵ = (log − log

This document provides solutions to several recurrence relations problems: 1. It uses the Master Theorem or other methods to solve six recurrence relations, explaining which case applies or why the Master Theorem does not apply. 2. It uses substitution or recursion trees to solve two recurrences, showing the steps to obtain the solutions. 3. It provides a justification for the solution to the bonus recurrence T(n) = 2T(n-1) + T(n-2) + 1 being exponential without proving it, finding the exponential base to be approximately 2.42.

Uploaded by

Ricardo Bruno
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSCI 3110 Assignment 6 Solutions

1. (14 points) Solve each of the following recurrences using the Master Theorem or, if
the Master Theorem is not applicable to the recurrence, state why. If the Master
Theorem applies, state which case is applicable and show that the recurrence satisfies
the conditions of this case.

(a) T (n) = 5T (n/3) + n log n


ANSWER: We have a = 5, b = 3, and f (n) = n log n. We begin by computing
nlogb a and comparing
( log a ) it to f (n). n
logb a
= nlog3 5 ≈ n1.465 . Thus,
n log n = O n b , so (case (i)) applies if we can find an appropriate ϵ. It is easy
to see that n log n = O nlog3 4 , and log3 4 = log3 5 − ϵ where
ϵ = (log3 5 − log3 4) > 0.
(b) T (n) = T (n/3) + T (2n/3) + n
ANSWER: The Master Theorem does not apply. This recurrence does not have
the correct form because there are recursive calls with different input sizes.
(c) T (n) = 3T (n/3) + n/ log n
ANSWER: The only( case of the ) Master Theorem that could apply is case (i)
because n/ log n = O nlog3 3 = n . However, n/ log n = Ω (n1−ϵ ), for all ϵ > 0, so
the Master Theorem does not apply.
(d) T (n) = 16T (n/4) + n2
ANSWER: We have a = 16, b =( 4, and f (n))= n2 . Case (ii) of the Master
Theorem applies because n2 = Θ nlog4 16 = n2 . Thus, T (n) = Θ (n2 log n).
(e) T (n) = 2T (n − 5) + n log n
ANSWER: This recurrence does not have the correct form because the input
size of the recursive calls is not a fraction of the original input size. The Master
Theorem does not apply.
(f) T (n) = 2T (n/3) + n
ANSWER: We have a = 2, b = 3, (and f (n) = n. )Case (iii) of the Master
Theorem may apply because n = Ω nlog3 2.5=log3 2+ϵ , for
ϵ = (log3 2.5 − log3 2) > 0. We now check the regularity condition
af (n/b) ≤ cf (n) which holds because 2f (n/3) = 2n/3 ≤ 2n/3 = cn = cf (n), for
c = 2/3), and all n0 ≥ 1. Thus, T (n) = Θ (n).
{
2T (n/2) + n3 if n is an even integer
(g) T (n) =
2T (n/2) + n2 if n is an odd integer
ANSWER: The only case ( of the Master
) Theorem that could apply is case (iii)
because n3 = Ω (n2 ) = Ω nlog2 2 = n . However, this recurrence fails the
regularity condition that af (n/b) ≤ cf (n), so the Master Theorem does not
apply.

2. (12 pts) Solve each of the following recurrences using substitution or a recursion tree.
Do not only state your solution—Show how you obtained it. That is, if you use
substitution, you must present the complete inductive proof that your solution is
correct. If you use a recursion tree, show the recursion tree and discuss how you
obtained the solution from the tree. Note that you are to prove matching upper and
lower bounds.

(a) T (n) = 4T (n/2) + n2


ANSWER:
T (n) = 4T (n/2) + n2
log2 n
f (n) = cn2 cn2

cn2 cn2 cn2 cn2 cn2


f ( n2 ) = 4 4 4 4 4· 4 = cn2

cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2 cn2
f ( n4 ) = 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16
16 · 16 = cn2

cn2 cn2 cn2


b2 i = ai ai · ai = cn2

b b b b b b b b bn2

P 
log2 n
T (n) = i=0 cn2 + bn2 = cn2 log2 n + bn2 = Θ(n2 lg n)

The depth of the tree is log2 n. Thus there are 4log2 n = nlog2 4 = n2 leaves, and
their cost is Θ (n2 ). The cost of the ith non-leaf level is:
( n )2
4i c (1)
2i
4i 2
=c n (2)
22i
4i
= c i n2 (3)
4
= cn2 (4)

Thus, the total cost is

( 2) ∑
log2 n
Θ n + cn2 (5)
( ) i=0
= Θ n2 + log2 n(cn2 ) (6)
( )
= Θ n2 lg n (7)

(b) T (n) = T (n/2) + T (n/4) + n


ANSWER: Since the first recursive call does Ω (n) work, T (n) = Ω (n). Lets
guess that T (n) = Θ (n) and prove the upper bound using substitution. So, our
claim is that T (n) ≤ cn.
For the base case, we consider 1 ≤ n < 4. We have that T (n) = Θ (1) ≤ cn, as
long as c is large enough. For n ≥ 4, we have that 1 ≤ n/2 < n and 1 ≤ n/4 < n,
so the inductive hypothesis applies to T (n/2) and T (n/4). Using this we have
that,

T (n) = T (n/2) + T (n/4) + n (8)


≤ c(n/2) + c(n/4) + n (9)
= (c/2 + c/4 + 1)n (10)
= (3/4c + 1)n (11)
≤ cn, (12)

as long as 1 ≤ c/4, that is, c ≥ 4.

3. (Bonus: 4 pts) What is the solution to T (n) = 2T (n − 1) + T (n − 2) + 1? You do not


need to prove your solution but provide some justification for it.
This is a tricky one. It is obviously exponential, so lets suppose that T (n) = xn , for
some exponential base. Then T (n) = xn = 2xn−1 + xn−2 . This means that
x2 = 2x + 1, so x2 − 2x − 1 = 0 which is a quadratic! Using the quadratic formula to
solve for the roots, √
−b ± b2 − 4ac
x= ,
2a
we see that the roots are

2± (−2)2 − 4(1)(−1)
x= (13)
√ 2
2± 4+4
x= (14)
√2
x=1± 2 (15)
√ ( √ )
Since 1 − 2 < 0, T (n) = Θ (1 + 2)n ≈ 2.42n . We could then use substitution to prove
this bound.

You might also like