0% found this document useful (0 votes)
600 views4 pages

CMPS 101 Fall 2009 Homework Assignment 4 Solutions

This document contains solutions to homework problems involving analysis of algorithms and recurrence relations using techniques like iteration, summation formulas, and the Master Theorem. Key points include: - Deriving a summation formula for a given recurrence relation T(n) using iteration. - Applying the Master Theorem to determine asymptotic bounds for various recurrence relations involving operations like T(n/c) + f(n). - Finding the largest value of a parameter a such that one recurrence relation S(n) is asymptotically faster than another recurrence T(n). - Proving properties of graphs like any connected graph G satisfying E(G) >= V(G) - 1 using mathematical induction.

Uploaded by

hoshgeldy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
600 views4 pages

CMPS 101 Fall 2009 Homework Assignment 4 Solutions

This document contains solutions to homework problems involving analysis of algorithms and recurrence relations using techniques like iteration, summation formulas, and the Master Theorem. Key points include: - Deriving a summation formula for a given recurrence relation T(n) using iteration. - Applying the Master Theorem to determine asymptotic bounds for various recurrence relations involving operations like T(n/c) + f(n). - Finding the largest value of a parameter a such that one recurrence relation S(n) is asymptotically faster than another recurrence T(n). - Proving properties of graphs like any connected graph G satisfying E(G) >= V(G) - 1 using mathematical induction.

Uploaded by

hoshgeldy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CMPS 101

Fall 2009
Homework Assignment 4 Solutions

1. (3 Points)
Consider the function T (n) defined by the recurrence formula
6 1≤ n < 3
T ( n) = 
 2T ( n / 3 ) + n n≥3
a. (1 Points) Use the iteration method to write a summation formula for T (n) .
Solution:
T (n) = n + 2T ( n / 3 )
= n + 2( n / 3 + 2T ( n / 3 / 3 ) )
= n + 2 n / 3 + 2 2 T ( n / 3 2 )
= n + 2 n / 3 + 2 2 n / 32 + 2 3 T ( n / 33 ) etc..

After substituting the recurrence into itself k times, we get

k −1
n
T (n) = ∑ 2  3 
i
i
+ 2 k T ( n / 3k  ) .
i =0

This process terminates when the recursion depth k is chosen so that 1 ≤ n / 3k  < 3 , which is
equivalent to 1 ≤ n / 3k < 3 , whence 3k ≤ n < 3k +1 , so k ≤ log 3 (n) < k + 1 , and hence k = log 3 (n) .
With this value of k we have T ( n / 3 k  ) = T (1or 2 ) = 6 . Therefore

log 3 ( n ) −1
n
T (n) = ∑
i =0
2 i  i  + 6 ⋅ 2 log3 ( n)  .
3 

b. (1 Points) Use the summation in (a) to show that T (n) = O (n)


Solution:
Using the above summation, we have

 log3 ( n ) −1 
T (n) ≤ n ∑ (2 / 3) i  + 6 ⋅ 2 log 3 ( n ) since x  ≤ x for any x
 i =0 
 ∞

≤ n  ∑ (2 / 3) i  + 6 n log 3 ( 2) adding ∞ -many positive terms
 i =0 
 1 
= n   + 6 n log3 ( 2) by a well known formula

 1 (2 / 3) 
= 3 n + 6 n log3 ( 2 ) = O(n) 2 < 3 ⇒ log 3 (2) < 1 ⇒ n log3 ( 2) = o(n)

Therefore T (n) = O (n) .

1
c. (1 Points) Use the Master Theorem to show that T (n) = Θ(n)
Solution:
Let ε = 1 − log 3 (2) > 0 . Then log 3 (2) + ε = 1 , and n = n log3 ( 2)+ε = Ω(n log3 ( 2)+ε ) . Also for any c in
the range 2 / 3 ≤ c < 1 , and any positive n, we have 2 (n / 3) = (2 / 3) n ≤ cn , so the regularity
condition holds. By case (3) of the Master Theorem T (n) = Θ(n) .

2. (6 Points)
Use the Master theorem to find asymptotic solutions to the following recurrences.
a. (1 Point) T (n) = 7T (n / 4) + n
Solution:
4 < 7 ⇒ 1 < log 4 (7) ⇒ log 4 (7) − 1 > 0 . Let ε = log 4 (7) − 1 . Then ε > 0 , and 1 = log 4 (7) − ε ,
whence n = n log 4 ( 7)−ε = O(n log 4 ( 7)−ε ) . By case (1) we have T (n) = Θ(n log 4 ( 7) ) .

b. (1 Point) T (n) = 9T (n / 3) + n 2
Observe that n 2 = n log3 ( 9) = Θ(n log3 (9 ) ) , and therefore T (n) = Θ(n 2 log(n)) by case (2).

c. (1 Point) T (n) = 6T (n / 5) + n 2
Solution:
Observe 6 < 25 ⇒ log 5 (6) < 2 ⇒ 2 − log 5 (6) > 0 . Let ε = 2 − log 5 (6) . Then log 5 (6) + ε = 2 ,
and n 2 = Ω(n log5 ( 6)+ε ) . Also for any c in the range 6 / 25 ≤ c < 1 , and for any positive n, we have
6(n / 5) 2 = (6 / 25)n 2 ≤ cn 2 , so the regularity condition holds. Therefore T (n) = Θ(n 2 ) by case (3)
of the Master Theorem.

d. (1 Point) T (n) = 6T (n / 5) + n log(n)


Solution:
log 5 (6) − 1
Observe log 5 (6) > 1 , so letting ε = , we have ε > 0 and 1 + ε = log 5 (6) − ε . Therefore
2
by l’Hopital’s rule

n log( n) n log(n) log(n)


lim ε
= lim ε
= lim =0,
n →∞ n log 5 ( 6 ) − n →∞ n 1+ n →∞ nε

showing that n log(n) = o(n log 5 ( 6)−ε ) ⊆ O(n log5 ( 6)−ε ) . Case (1) now gives T (n) = Θ(n log5 ( 6) ) .

e. (1 Point) T (n) = 7T (n / 2) + n 2
Solution:
Observe that 7 > 4 ⇒ log 2 (7) > 2 , so upon setting ε = log 2 (7) − 2 we have ε > 0 . It follows that
2 = log 2 (7) − ε , whence n 2 = n log 2 (7 )−ε = O (n log 2 ( 7 )−ε ) . Case 1 now gives T (n) = Θ(n log 2 ( 7) ) .

f. (1 Point) S (n) = aS (n / 4) + n 2 (Note: your answer will depend on the parameter a.)
Solution:
We have three cases to consider corresponding to the three cases of the Master Theorem:
Case 1: a > 16 ⇒ log 4 (a ) > 2 ⇒ ε = log 4 (a) − 2 > 0 ⇒ n 2 = O(n log 4 ( a )−ε ) , so S (n) = Θ(n log 4 ( a ) ) .

2
Case 2: a = 16 ⇒ log 4 (a ) = 2 ⇒ n 2 = Θ(n log 4 ( a ) ) , whence S (n) = Θ(n 2 log(n)) .
Case 3: 1 ≤ a < 16 ⇒ log 4 (a) < 2 ⇒ ε = 2 − log 4 (a ) > 0 ⇒ n 2 = Ω(n log 4 ( a )+ε ) . Further, for any c
in the range a / 16 ≤ c < 1 we have a(n / 4) 2 = (a / 16)n 2 ≤ cn 2 , showing that the regularity condition
holds. Therefore S (n) = Θ(n 2 ) .

3. (1 Point) p.75: 4.3-2


The recurrence T (n) = 7T (n / 2) + n 2 describes the running time of an algorithm A. A competing
algorithm B has a running time of S (n) = aS (n / 4) + n 2 . What is the largest integer value for a such
that B is a faster algorithm than A (asymptotically speaking)? In other words, find the largest integer a
such that S (n) = o(T (n)) .
Solution:
We seek the largest integer a for which S (n) = o(T (n)) . Using parts (e) and (f) of the previous
problem, we find that S (n) = o(T (n)) in cases 2 and 3 since 4 < 7 ⇒ 2 < log 2 (7) and hence
n 2 = o(n log 2 (7 ) ) , and n 2 log( n) = o(n log2 ( 7 ) ) . In case 1 we have S (n) = o(T (n)) if and only if
n log 4 ( a ) = o(n log2 ( 7 ) ) , i.e. if and only if log 4 (a ) < log 2 (7) . Thus we seek the largest integer a such that
a < 4 log2 (7 ) = 7 log 2 ( 4 ) = 7 2 = 49 . The largest such integer is a = 48 .

4. (1 Point)
Let G be an acyclic graph with n vertices, m edges, and k connected components. Show that
m = n − k . (Hint: use the fact that | E (T ) | = | V (T ) | − 1 for any tree T, from the induction handout.)
Proof:
Let T1 , T2 , K, Tk , be the connected components of G, each of which is necessarily a tree. Let
ni =| V (Ti ) | , and mi =| E (Ti ) | , for 1 ≤ i ≤ k . By a theorem proved in the induction handout, we have
mi = ni − 1 , for 1 ≤ i ≤ k . Therefore

k k k k
m = ∑ mi =
i =1
∑ (ni − 1) =
i =1
∑ ni − ∑1 = n − k .
i =1 i =1
///

5. (1 Point) (Appendix B.4 problem 3)


Show that any connected graph G satisfies E (G ) ≥ V (G ) − 1 . (Hint: use induction on the number
of edges. Note: this hint wrongly said “induction on the number of vertices” in the original statement
of the problem.)

Proof:
Let G = (V , E ) be a connected graph, and suppose | E | = 0 . Since G is connected we must have
| V | = 1 , whence | E | ≥ | V | − 1 , and so the base case is satisfied.

Now suppose | E | > 0 and assume the result holds for any graph with fewer than | E | edges. In other
words, we assume that for all graphs G ′ = (V ′, E ′) with | E ′ | < | E | that E ′ ≥ V ′ − 1 . Now pick any
edge e in G and remove it, and let G − e denote the resulting graph. We have two cases to consider.
3
Case 1: G − e is connected. In this case we apply the induction hypothesis to G − e = (V , E − e) which
has fewer edges than G. We conclude that | E − e | ≥ | V | −1 , so that | E | −1 ≥ | V | −1 , and therefore
| E | ≥ | V | > | V | −1 , as required.
Case 2: G − e is disconnected. In this case G − e consists of two connected components. (**See the
claim and proof below, which are not necessary for full credit on this problem.) Call them
H 1 = (V1 , E1 ) and H 2 = (V2 , E2 ) . Note that both H 1 and H 2 have fewer edges than G, so we may
apply the induction hypothesis to obtain | E1 | ≥ | V1 | −1 and | E2 | ≥ | V2 | −1 . Therefore

| E | = | E1 | + | E2 | +1
≥ (| V1 | −1) + (| V2 | −1) + 1 (by the induction hypothesis)
= | V1 | + | V2 | −1
= | V | −1 (no vertices were removed so | V1 | + | V2 | = | V | ).

The result now holds for all connected graphs by induction. ///

Claim**: Let G be a connected graph and e ∈ E (G ) , and suppose that G − e is disconnected. (Such
an edge e is called a bridge). Then G − e has exactly two connected components.

Proof: Since G − e is disconnected, it has at least two components. We must show that it also has at
most two components. Let e have end vertices u, and v. Let Cu and C v be the connected components
of G − e that contain u and v respectively. Choose x ∈V (G ) arbitrarily, and let P be an x-u path in G.
Either P includes the edge e, or it does not. If P does not contain e, then P remains intact after the
removal of e, and hence P is an x-u path in G − e , whence x ∈ Cu . If on the other hand P does contain
the edge e, then e must be the last edge along P from x to u.

x v u
P
e

In this case P − e is an x-v path in G − e , whence x ∈ C v . Since x was arbitrary, every vertex in G − e
belongs to either Cu or C v , and therefore G − e has at most two connected components. ///

You might also like