CS 3510 Homework 1 Q
CS 3510 Homework 1 Q
• Please TYPE your solutions using Latex or any other software. Handwritten
solutions will not be accepted.
• Unless otherwise stated, use log to the base 2. receive more credit. If we ask
for a specific running time, a correct solution achieving it will receive full credit
even if a faster solution exists.
(b.) n3.1415
log 50
(c.) 100n2 +n
(d.) 22024
(f.) 1024log n
(e.) f (n) = n!
3.) (30 points) Suppose you have two non-negative integers x, y each stored in binary represen-
tation as arrays of n bits (ordered least significant digit to most significant digit). We want to
determine if x > y, y > x, or x = y.
(a.) Design an algorithm in English and mathematical expressions that accomplishes this. Also,
provide pseudo-code for the same.
(b.) What is the running time of this algorithm, in the worst case over inputs x, y, using Θ(·)
notation, and assuming comparing two bits takes time 1.
(c.) Can you prove (or argue) that this running time is optimal (up to constants) over all correct
algorithms?
(d.) What is the fastest your algorithm can run (the best case scenario over inputs x, y)?
4.) (20 points) Assume n is a power of 4. Assume we are given an algorithmic routine f (n) as
follows:
function f(n):
if n>1:
for i in range(5):
f(n/4)
for i in range(n*n):
print("Hello")
else:
print("World")
(a.) What is the running time for this function f (n)? Justify your answer. (Hint: Compute the
recurrence first)
(b.) How many times will this function print “World”? Please provide the exact number in terms
of the input n. Justify your answer.
5.) (30 points) For any number n, such that n is a power of 2, the Star matrix, Sn is defined as
follows:
if n = 1, Sn = 1
3S n2 I n2
if n > 1, Sn =
S n2 −2S n2
(a.) Design an O(n log n) algorithm (by explaining it in English) that calculates the vector Sn · v,
where n is a power of 2 and v is a vector of length n. Pseudo-code is not required.
(b.) Justify the runtime of your algorithm by providing a recurrence relation for the runtime and
solving it.
Practice Problem
Note: This problem won’t be graded.
Suppose Malav and Saigautam are trying to come up with Divide & Conquer approaches to some
problem P with input size n. Malav comes up with a solution that utilizes 6 sub-problems of size
n/3 with time n2 to combine subproblems,
√ while Saigautam comes up with a solution that utilizes
8 sub-problems of size n/4 with time n n + n to combine subproblems.
(a.) Find the runtime of both approaches, and choose the algorithm that runs faster at large
input size n. If both are the same speed, specify this.
(b.) Let’s say Jayanee also tries to solve P using an algorithm of her own. She utilizes 10 sub-
problems of size n/5 with time log n to combine subproblems. Is this algorithm faster than
the one you chose in part (a)? Why or why not?