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

Comp Sci analysis Assignment4-Questions

Homework Assignment 4 requires students to submit solutions on Crowdmark by February 14, 2025. The assignment consists of several questions related to algorithm analysis, including recurrence relations and proofs. Students must provide detailed solutions, including derivations and justifications for their answers.

Uploaded by

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

Comp Sci analysis Assignment4-Questions

Homework Assignment 4 requires students to submit solutions on Crowdmark by February 14, 2025. The assignment consists of several questions related to algorithm analysis, including recurrence relations and proofs. Students must provide detailed solutions, including derivations and justifications for their answers.

Uploaded by

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

Homework Assignment 4

due Friday, February 14, 2025, 11:59pm


Submit solutions on Crowdmark, not UM Learn. A Crowdmark link will be sent to your UM e-mail.
When uploading to Crowdmark, a separate file will be required for each part of each question.

a
1. This question refers to the following code. Assume that the / symbol represents integer division: a/b = b .
Let A be an integer array.

1 // pre: (A.length >= 1) ∧ (0 <= low,high < A.length)


2 void recursiveFnc(int[] A, int low, int high)
3 if (low < high-5)
4 localFnc(A, low, high)
5 recursiveFnc(A, (5*low+high)/6 + 1, (low+high)/2)
6 recursiveFnc(A, (2*low+high)/3 + 1, (low+2*high)/3)

Let n = high − low + 1. Assume that localFnc(A, low, high) performs some operation on the entries
A[low], . . ., A[high] inclusive, and that if this function acts on n entries, its cost is n2 .

(5 marks) (a) Let T (n) be the cost of recursiveFnc() as a function of the input size n. Find the recurrence relation
that defines T (n), and show your work.
You will need to use the floor and/or ceiling functions. The only variable should be n: the indices low
and high should not appear in your final answer. Once you have eliminated low and high in favor of n,
you do not need to simplify your expressions any further.

(2 marks) (b) Prove the following statement:


3r − 1 3s − 3
for all integers r, s, if r, s ≥ 1, then is an integer, and is an integer.
2 6
Hint: you may use the Fundamental Theorem of Arithmetic, i.e., every integer greater than 1 can be written
exactly one way as a product of prime numbers (ignoring the ordering of the factors).

(3 marks) (c) In the special case where n = 3 r for some integer r ≥ 0, prove that your recurrence relation from part
(a) can be simplified to the following form:

d, n≤c
T (n) =
aT nb + f (n), n > c


You may use the fact stated in part (b) in your proof.

2. This question refers to the following recurrence relation.



 1, n=1
T (n) = 4, n=2
 T (n − 2) + n2 , n>2

(6 marks) (a) Use the substitution method to derive a closed-form expression for this recurrence relation. Consider
the case where n is even only. You do not need to repeat your calculation for the case where n is odd.
Simplify your answer until no summation notation remains.

(4 marks) (b) Prove that your closed-form expression in part (a) is correct for all n ≥ 1 using mathematical induction.

COMP 2080: Analysis of Algorithms (Winter 2025) Page 1 of 4


3. This question refers to the following recurrence relation. You should assume that n is a power of 9.

1, n≤9
T (n) = p
3T 9n + 2 n, n > 9


(6 marks) (a) Draw the recursion tree for the recurrence relation. Include at least three rows of the tree. Calculate the
sum of each row, and then derive an expression for the sum of all entries in the tree. Use the result to
conjecture a function g(n) so that T (n) ∈ Θ(g(n)).
You should remove unnecessary constants and additive terms from your g(n), that is: if you have an
expression g1 (n), and you can obtain an expression g2 (n) by deleting some constants and additive terms
from g1 such that g2 (n) = Θ(g1 (n)), then you should use g2 (n) for your answer.

(2 marks) (b) Explain which case of the Master Theorem applies to the recurrence relation, and use that case to prove
your conjecture from part (a).

4. For each of the following recurrence relations, state which case of the Master Theorem can be applied and
justify your answer, then use the Master Theorem to find a function g(n) such that T (n) ∈ Θ(g(n)).

(2 marks) (a) 
1, n≤2
T (n) = n

6T 3 + n log(n),
2
n>2

(2 marks) (b)
n=1

1,
T (n) = n

8T 2 + 3n3 + n2 , n>1

(2 marks) (c) 
1, n≤3
T (n) = n

7T 4 + n + log(n), n>3

(6 marks) 5. Give a complete proof that none of the 3 cases of the Master Theorem apply to the following recurrence
relation. 
1, n≤1
T (n) =
3T 3n + logn n , n > 1


COMP 2080: Analysis of Algorithms (Winter 2025) Page 2 of 4


Definitions and Facts
Definitions
• The symbol Z represents the set of integers {. . . , −2, −1, 0, 1, 2, . . .}.
• The symbol N represents the set of positive integers {1, 2, 3, . . .}.
• The symbol R represents the set of real numbers.
• An integer n is even if there exists an integer k such that n = 2k.
• An integer n is odd if there exists an integer k such that n = 2k + 1.
• The floor of x, denoted by ⌊x⌋, is the largest integer that is less than or equal to x.
• The ceiling of x, denoted by ⌈x⌉, is the smallest integer that is greater than or equal to x.
• For every positive integer x, the double factorial x!! is defined as the product 1 · 3 · 5 · · · (x − 4) · (x − 2) · x when x is odd, and, defined
as the product 2 · 4 · 6 · · · (x − 4) · (x − 2) · x when x is even.

Floors/Ceilings
For any real number x and any real number y ̸= 0:
• −⌊x⌋ = ⌈−x⌉ and −⌈x⌉ = ⌊−x⌋
• for any integer k: ⌊k⌋ = ⌈k⌉ = k
• for any integer k: k + ⌊x/ y⌋ = ⌊k + x/ y⌋
• for any integer k: k + ⌈x/ y⌉ = ⌈k + x/ y⌉
• for any integer k: ⌊(k + 1)/2⌋ = ⌈k/2⌉ and ⌈(k − 1)/2⌉ = ⌊k/2⌋
⌊x/a⌋ x ⌈x/a⌉ x
• for any integers a, b: ⌊ b ⌋ = ⌊ ab ⌋ and ⌈ b ⌉ = ⌈ ab ⌉

Exponentials and Logarithms


For all a, b, c > 0 and all x, y ∈ R:
p
a0 = 1 a1 = a for integer k > 1: a1/k = k a
ax
a x a y = a x+ y a−1 = 1/a = a x− y
x y y x
ay
(a ) = (a ) = a xy
(a b) x = a x b x a < b if and only if a c < b c

For all a, b > 1, and all x, y > 0:

loga (1) = 0 loga €a =Š1 aloga (x) = x and loga (a x ) = x


x log b x
loga (x y) = loga (x) + loga ( y) loga y = loga (x) − loga ( y) loga x = log b a
1
loga (x y ) = y loga (x) loga (1/x) = − loga x log b a = loga b
x < y if and only if loga (x) < loga ( y)

Summation Identities

b n
X X n(n + 1)
1= b−a+1 j=
j=a j=1
2
n n
X
2 n(n + 1)(2n + 1) X n2 (n + 1)2
j = j3 =
j=1
6 j=1
4
n ∞
X q n+1 − 1 X 1
∀q > 0, q ̸= 1, qj = ∀q, 0 < q < 1, qj =
j=0 
q−1 j=0
1−q
  
Xb Xb Xb b
X b
X
( f ( j) + g( j)) =  f ( j) +  g( j) c · f ( j) = c · f ( j) for any constant c
j=a j=a j=a j=a j=a

COMP 2080: Analysis of Algorithms (Winter 2025) Page 3 of 4


Asymptotics
In these statements, a, b and c are constants (i.e., they are not functions of n), and f , g, h, f1 , f2 , g1 and g2 are
functions that map Z+ → R+ .

Group 1: the hierarchy summarized. For all constants a > 0 and b > 0 and c > 0:
(1.1) if a > 1, then c ∈ o(loga (n))
(1.2) if a > 1, then loga (n) ∈ o(n b )
(1.3) if a < b, then na ∈ o(n b )
(1.4) if b > 1, then na ∈ o(b n )
(1.5) if 1 < a < b, then a n ∈ o(b n )
(1.6) a n ∈ o(n!)

Group 2: transitivity.
(2.1) if f ∈ O(g) and g ∈ O(h), then f ∈ O(h)
(2.2) if f ∈ Ω(g) and g ∈ Ω(h), then f ∈ Ω(h)
(2.3) if f ∈ o(g) and g ∈ o(h), then f ∈ o(h)
(2.4) if f ∈ ω(g) and g ∈ ω(h), then f ∈ ω(h)

Group 3: conditionals and biconditionals.


(3.1) f ∈ Θ(g) if and only if f ∈ O(g) and f ∈ Ω(g)
(3.2) f ∈ O(g) if and only if g ∈ Ω( f )
(3.3) f ∈ o(g) if and only if g ∈ ω( f )
(3.4) if f ∈ o(g), then f ∈ O(g)
(3.5) if f ∈ ω(g), then f ∈ Ω(g)
/ Ω(g)
(3.6) If f ∈ o(g), then f ∈
(3.7) If f ∈ ω(g), then f ∈
/ O(g)

Group 4: addition.
(4.1) if f ∈ O(h) and g ∈ O(h), then f + g ∈ O(h)
(4.2) if f ∈ Ω(h), then f + g ∈ Ω(h)
(4.3) if f ∈ o(h) and g ∈ o(h), then f + g ∈ o(h)
(4.4) if f ∈ ω(h), then f + g ∈ ω(h)

Group 5: multiplication.
(5.1) for any constant c > 0, c f ∈ Θ( f )
(5.2) if f1 ∈ O(g1 ) and f2 ∈ O(g2 ) then f1 f2 ∈ O(g1 g2 )
(5.3) if f1 ∈ Ω(g1 ) and f2 ∈ Ω(g2 ) then f1 f2 ∈ Ω(g1 g2 )
(5.4) if f1 ∈ O(g1 ) and f2 ∈ o(g2 ) then f1 f2 ∈ o(g1 g2 )
(5.5) if f1 ∈ Ω(g1 ) and f2 ∈ ω(g2 ) then f1 f2 ∈ ω(g1 g2 )

COMP 2080: Analysis of Algorithms (Winter 2025) Page 4 of 4

You might also like