Homework 1
Homework 1
Winter, 2024
Due Wednesday, January 17 at 11:59 PM
Background: order notation, induction , loop invariants, simple analysis of
algorithms
Ungraded Problems
1. Which of the following pairs of functions are of the same order? (By same
order, I mean that they have the Θ relation.) Explain your answer
1
Graded Problems - 25 points each
1. Prove that, if for positive integer-valued functions f, g, f ∈ Θ(g), and h
is a strictly increasing positive integer valued function, that f (h(n)) ∈
Θ(g(h(n)). Is the converse always true?
2. Consider the following word puzzle. You are given a vocabulary list of
n, k-letter words, a starting k-letter word, and an ending k-letter word.
You want to find a way to change the starting word to the ending word
one letter at a time, always being on the list of vocabulary words. Define
a graph where solutions correspond to certain paths in the graph. Be
sure to specify what the vertices and edges of your graph are, and exactly
which paths correspond to solutions. For example, say k = 4 and n = 15,
the starting word is SHOW and the ending word is T ELL, and the list
contains those two words and
,
CROP, DROP, CLOP, COOP, COOL, T OOL, T OLL
. Then one solution is
3. One vector of real numbers (x1 , ..xd ) dominates another vector (y1 , ..yd )
if xi ≥ yi for i = 1...d. (Think of each co-ordinate as a quantity that
might be better or worse for some alternatives, e.g., speed and memory
for computer architectures. ⃗x dominates ⃗y if it is at least as good in all
respects.) Given a set of n vectors in d dimensions S, ⃗x is Pareto Optimal
if there is no ⃗y ∈ S, ⃗y ̸= ⃗x, such that ⃗y dominates ⃗x. For two dimensions,
give an efficient algorithm that returns the list of Pareto Optimal elements
of S. (Extra: how about for larger values of d?)
4. Experimental Evaluation of Triangle Algorithm.
Implement a triangle finding algorithm as in the last ungraded problem
and test it on many random graphs where each edge is present with proba-
bility 1/2. Try it for n = |V | as many different powers of 2 as you can. Plot
time vs. input size on a log vs. log curve. Does the algorithm’s observed
time fit the analysis? Why or why not? Then do the same experiment for
random bipartite graphs with n vertices on each side.