You are on page 1of 1

University of Engineering and Technology

Department of Electrical Engineering


EE 234: Data Structures and Algorithms
Spring 2022

Problem Set 1 Questions: 4 Date: January 31, 2022 Due: February 7 , 2022

Question 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 points
For the following group of functions, sort the functions (along with a brief justification) in increas-
c c
ing order of asymptotic (big-O) complexity. Please note that ab = a(b ) , and you may assume
that n = 2m for some m. This assumption is legal because of a mathematical theorem. However,
we will just use it as a common sense “approximation”.
(a) 234n , (lg n)234 , n234 , n lg n234
n n+1 3
(b) 32 , 22 , 22n , 8n , 2n
3 3
(c) n3 lg n , (lg lg n)3 , lg((lg n)3 ), lg(3n ), (lg n)lg(n )
Question 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 points
Find the correct asymptotic complexity of an algorithm with runtime
(a) T (n) where T (1) = Θ(1), T (n) = c + 2T (n − 1) where c is a constant.
(b) T (n), where T (1) = Θ(1), T (n) = 2T (n/2) + Θ(n)
(c) T (n, n) where
T (x, c) = Θ(x), c ≤ 2
T (c, y) = Θ(y), c ≤ 2
T (x, y) = Θ(x + y) + T (x/2, y/2)

Question 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 points
Prove that n3 − 12n2 = Ω(n2 ). You must use the definition of Ω to prove it.
Question 4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 points
. This question is regarding the peak-finding algorithm discussed in class and the code handed
out. Some helpful hints:
ˆ Use the visualizer. It is really helpful.
ˆ Read the code intelligently. You do not need to read all the files in all their detail. The
algorithms.py file is important. Sometimes the peak.py is also helpful. The generate.py file
allows you to generate random problems. You should run the main.py file and see the results
using the visualizer.
ˆ You can assume that algorithms 1 and 4 are correct. However, one of the remaining two
algorithms is incorrect.
ˆ You always run these algorithms on problems of size n × n, and can assume that n = 2m as
suggested earlier.
(a) Prove that the running time of algorithm 1 is Θ(n lg n).
(b) Would the running time change if we used a more efficient 1-dimensional local peak-finding
algorithm (that runs in Θ(lg n))? Would the algorithm be correct? Prove or disprove your
assertion.
(c) Argue that the running time of algorithm 2 is Θ(n2 ).
(d) Prove or disprove that algorithm 2 is correct for all problems with n ≤ 3 × 3.
(e) Prove or disprove that algorithm 3 is correct for all problems with n ≤ 3 × 3.
(f) One of algorithm 2 or algorithm 3 is incorrect. Which one? Give a 5 × 5 example to show
its incorrectness. Please submit the answer to this question in the computer science lab.

You might also like