This preview shows pages 1–2. Sign up to view the full content.
CS 473: Fundamental Algorithms, Spring 2011
HW 2
Homework is due by
Monday, 23:59:59, February 7
Problem 1 is due by
Sunday, 23:59:59, February 6
This homework contains four problems.
Read the instructions for submitting homework on
the course webpage
.
Collaboration Policy:
For this homework, Problems 2–4 can be worked in groups of up to three
students.
Problem 1 should be answered in Compass as part of the assessment HW2Online and
should be done individually.
1. (30 pts.) Short questions to be answered on compass individually.
2. (30 pts.)
•
(15 pts.)
Four cycles.
Design and analyze an algorithm that takes as input an undirected graph
G
= (
V,E
) and
determines whether
G
contains a simple cycle (that is, a cycle which does not intersect
itself) of length four. Its running time should be at most
O
(

V

3
). You may assume that
the input graph is represented either as an adjacency matrix or with adjacency lists,
whichever makes your algorithm simpler.
Solution
:
We report that
G
has a simple cycle of length four if and only if there exist a pair
of distinct vertices
x
and
y
that have at least two common neighbors. Clearly there
are
O
(

V

2
) pair of distinct vertices. We check if
x
6
=
y
have at least two common
neighbors or not in
O
(

V

) time as follows: Consider each vertex
z
∈
Adj
(
x
) and check
if
z
∈
Adj
(
y
), which can be done in
O
(1) time using hashing. The total running time is
clearly
O
(

V

3
).
Rubrik
:
•
10pts:
If the writeup gives a correct algorithm. If the algorithm is incomplete
but gives a key idea that could lead to a correct algorithm, it gets 5pts.
•
5pts:
If the algorithm has a running time
O
(

V

3
).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 Chekuri,C
 Algorithms

Click to edit the document details