Analysis of Algorithms

96 views 8:21 am 0 Comments March 23, 2023

COMP 2080
Analysis of Algorithms
Department of Computer Science
University of Manitoba
COMP 2080 Winter 2023 – Assignment 5
This assignment is due by 11:59pm on Wednesday March 8.
Submission instructions. Your assignment will be submitted in Crowdmark and not in UM
Learn. A Crowdmark invitation will be sent to your U of M email.
Proofs will be graded on both correctness and presentation. Clearly explain all of your steps.
The total number of points is 30.
Questions
1. This question refers to the following recurrence relation.
T(n) =  1 2, n T(n 1) + n, n = 0 1
(a)
[2 marks] Assume that n is much larger than 1. Use the recurrence relation to write
T(n) in terms of T(n 1), then in terms of T(n 2), then in terms of T(n 3). You can
perform more substitutions if you wish in order to see the pattern.
(b)
[2 marks] Conjecture an expression for T(n) in terms of T(n j), for an arbitrary j.
Your expression can involve summation notation. For what range of
j values does your
conjecture apply?
(c)
[2 marks] Using part (b), conjecture a closed-form solution for T(n) as a function of n.
Evaluate any summation notation. Here are two useful identities that hold for any
n 1
and any constant
q, q > 0 and q ̸= 1.

n1
X
qn 1
q 1 ,
n1
X
nqn + 1
q 1
qn+1 1
(
q 1)2
k
=0
qk = k
=0
kqk =

(d) [3 marks] Prove your conjecture using mathematical induction.
2. This question refers to the following recurrence relation.
T(n) =

0, n = 0
98
, n = 1
T(n 2) + n3, n 2
(a) In parts (i) – (iii), consider the case where
n is even only. You do not need to repeat
your calculation for the case where
n is odd.
1

COMP 2080
Analysis of Algorithms
Department of Computer Science
University of Manitoba
(i)
[2 marks] Assume that n is much larger than 1. Use the recurrence relation to write
T(n) in terms of T(n 2), then in terms of T(n 4), then in terms of T(n 6).
(ii)
[2 marks] Conjecture an expression for T(n) in terms of T(n2j), for an arbitrary
j. For what range of j values does your conjecture apply?
(iii)
[2 marks] Using part (ii), conjecture a closed-form solution for T(n) as a function of
n. Evaluate any summation notation. Hint: do not expand out a term like (n2k)3.
Instead, define a new index of summation that makes the summand simpler.
(b)
[3 marks] The closed form solution to this recurrence relation is
T(n) = 1
8
n2(n + 2)2, n 0.
Prove that this solution is correct using strong mathematical induction. Note that this
formula holds for both even and odd
n. Do not proceed by cases in the induction step.
3. This question refers to the following code. Assume that the
/ symbol represents integer
division:
a/b = ab . Let A be an integer array.
1
// pre: (A.length >= 1) (0 <= j,k < A.length)
2 void recursiveFnc(int[] A, int j, int k)
3 if (j < k-6)
4 localFnc(A, j, k)
5 recursiveFnc(A, (7*j+k)/8 + 1, (5*j+3*k)/8)
6 recursiveFnc(A, (3*j+5*k)/8 + 1, (j+7*k)/8)
Let n = k j + 1. Assume that localFnc(A, j, k) performs some operation on the entries
A[j], . . ., A[k] inclusive, and that if this function acts on n entries, its cost is n3/2.
(a)
[3 marks] Let T(n) be the cost of recursiveFnc() as a function of the input size n.
Find the recurrence relation that defines
T(n).
Use the simplified conventions for counting steps that were described and used in the
Week 7 notes. For example, a fixed number of steps that does not depend on the size
of
n can be approximated by 1. A local cost function f(n) can be approximated by its
largest term.
You will need to use the floor and/or ceiling functions. The only variable should be
n:
the indices
j and k should not appear. Once you have eliminated j and k in favor of n,
you do not need to simplify your expressions any further.
For the remainder of Question 3, assume that
n = 4r for some integer r 0.
2

COMP 2080
Analysis of Algorithms
Department of Computer Science
University of Manitoba
(b)
[2 marks] In the special case where n = 4r for some integer r 0, show that your
recurrence relation from part (a) can be simplified to the following form.
T(n) =  c, n aT nb  + f(n), n > d d
(c) [4 marks] Draw the recursion tree for your recurrence relation from part (b). Include
enough rows to establish a pattern for the entries. Calculate the sum of each row, and
find a lower bound and an upper bound for the sum of all of the entries in the tree. Use
that result to conjecture a function
g(n) so that T(n) Θ(g(n)). You do not need to
prove your conjecture.
4.
[3 marks] For each of the following recurrence relations, explain which case of the Master
Theorem applies, then use the Master Theorem to find a function
g(n) such that T(n)
Θ(g(n)).
(a)
T(n) =  14, n T 16 n  + 5n2/3, n >15 15
(b)
T(n) =  130, n T n3  + 4n3 n, n >2 2
(c)
T(n) =  1 6, n T n6  + 15n, n >5 5
3