0% found this document useful (0 votes)
6 views2 pages

Homework 1

The document outlines the CSE 202 Homework 1 for Winter 2024, due on January 17. It includes ungraded and graded problems covering topics such as order notation, induction, loop invariants, and algorithm analysis. The homework consists of various mathematical and algorithmic challenges, including function comparisons, Fibonacci sequence proofs, urn problems, and graph algorithms.

Uploaded by

jsliang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Homework 1

The document outlines the CSE 202 Homework 1 for Winter 2024, due on January 17. It includes ungraded and graded problems covering topics such as order notation, induction, loop invariants, and algorithm analysis. The homework consists of various mathematical and algorithmic challenges, including function comparisons, Fibonacci sequence proofs, urn problems, and graph algorithms.

Uploaded by

jsliang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 202 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

(a) n log(n2 ) and n log n


(b) 2log n and 22 log n .
(c) 2n and 2n + 2n−1 + 2n−2 + ...1
(d) n2 and n2 + (n − 1)2 + (n − 2)2 + ...4 + 1
(e) n log n and log(n!)

2. The Fibonnaci sequence F ibi is defined by the recurrence F ib0 = F ib1 = 1,


F ibi+1 = F ibi + F ibi−1 for i ≥ 1.
Give a simplified expresssion for F ib1 +F ib3 +F ib5 +...F ib2i+1 , and prove
your answer.
3. You start with some number of red balls in a red urn, and some number
of green balls in a green urn. At each step, you pick a ball arbitrarily from
each urn, and switch both to the other urn. Prove that, at all times, there
are the same number of red balls in the green urn as there are green balls
in the red urn.
4. Recurrence:
√ Let T (n) be the function given by the recursion: T (n) =
nT (⌊ n⌋) for n > 1 and T (1) = 1. Is T (n) ∈ O(nk ) for some constant k,
i.e. is T bounded by a polynomial in n? Prove your answer either way.
(Note: logic and definition of O notation are more important than exact
calculations for this problem.)
5. Reasoning about order: Let f (n) be a positive, integer-valued function on
the natural numbers that is non-decreasing. Show that if f (2n) ∈ O(f (n)),
then f (n) ∈ O(nk ) for some constant k. Is the converse also always true?
(Note: be careful in your statement of the converse. this is the difficult
part)
6. Triangles: A triangle in a graph are 3 nodes any two of which are adjacent.
Present two algorithms for determining whether a graph has a triangle,
one if the graph is given as an adjacency matrix and the other if it is given
in adjacency list format. Analyze these algorithms in terms of both the
number of nodes n and the number of edges m.

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

SLOW, ST OW, ST OP, SHOP, SLOP, CHOP

,
CROP, DROP, CLOP, COOP, COOL, T OOL, T OLL
. Then one solution is

SHOW, SLOW, SLOP, CLOP, COOP, COOL, T OOL, T OLL, T ELL

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.

You might also like