Anuj Thomas Mathew 1001237364
Anuj Thomas Mathew 1001237364
3-1:
Show that the solution of T(n) = T(n-1) + n is O(n^2).
Solution:
Applying recursion tree, T (n) = n (n 1) (n 2) 1 = n(n 1)/2 = (n 2 ).
We must prove the T (n) = (n 2 ) by induction. The inductive hypothesis is T (n) = cn2 for some
constant c > 0.
T (n) = T (n 1) + n
c(n 1)2 + n
= cn2 2cn + c + n
cn2
We can prove the T (n) = O(n 2 ) by similar arguments.
4.3-2:
Show that the solution of T (n) = T (n/2) + 1 is O(lg n)
Solution:
We guess that the solution is T (n) = O(lg n). We must prove that T (n) c lg n for appropriate c
> 0. We start by assuming that this bound holds for n/2, that is that T (n/2) c lg(n/2).
Substituting into the recurrence yields
T (n) c lg(n/2) + 1
c lg(n/2) + 1
= c lg n c lg2 + 1
= c lg n c + 1
= c lg n
if c 1
the last step holds as long as c 1. For the base case, it suffices to show that T (2) c lg 2 for
some c 1. T (2) = T (1) + 1 or T (2) = 2 assuming T (1) = 1. Thus T (2) c lg 2 if c 2.
4.5-1:
Use the master method to give tight asymptotic bounds for the following recurrences:
i)
T(n) = 2T(n/4) + 1
Solution:
For this recurrence, we have a = 2, b = 4, f (n) = 1, and thus we have that nlogba = nlog42.
Since f (n) = 1 = O(nlog42-), where = 0.2, we can apply case 1 of the master theorem
and conclude that the solution is T(n) = (nlog42) = (n1/2) = (sqrt(n)).
ii)
iii)
T(n) = 2T(n/4) + n
Solution:
For this recurrence, we have a = 2, b = 4, f (n) = n, and thus we have that nlogba = nlog42.
Since f (n) = (nlog42+) , where = 0.2, we can apply case 3 of the master theorem if
we can show that the regularity condition holds for f (n).
To show the regularity condition, we need to prove that af (n/b) cf (n) for some
constant c < 1 and all sufficiently large n. If we can prove this, we can conclude that
T(n) = (f (n)) by case 3 of the master theorem.
Proof of the regularity condition:
af (n/b) = 2(n/4) = n/2 cf (n) for c = 0.7, and n 2.
So, we can conclude that the solution is T(n) = (f (n)) = (n).
iv)