CS41 Homework 4

Transcription

CS41 Homework 4
CS41 Homework 4
due 10AM Thursday February 19
Write your solution using LATEX. Submit this homework using handin41. For this and most/all
future homeworks, you will work with a partner. This week I have assigned you partners. It is still
OK to discuss approaches with others at a high level, but most of your discussions should be just
with your lab partner.
The only exception to this rule is work you’ve done with someone while in lab. In this case,
note who you’ve worked with and what parts were solved during lab.
If there are questions about academic integrity, please visit the section on Academic Integrity
on the course website (www.cs.swarthmore.edu/~brody/cs41/s15/expectations.php). If you
still have questions, please contact me.
Note: Make sure your homework includes the names of both lab partners. Only one partner
needs to submit files. Make sure the files you submit are in the cs41/hw/xx directory before calling
handin41.
The lab and homework this week center on graph algorithms for undirected graphs. The following definitions might be helpful/relevant.
• A path P on a graph G = (V, E) is a sequence of vertices P = (v1 , v2 , . . . , vk ) such that
(vi , vi+1 ) ∈ E for all 1 ≤ i < k.
• A path is simple if all vertices are distinct.
• The length of a path P = (v1 , . . . , vk ) equals k − 1. (Think of the path length as the number
of edges needed to get from v1 to vk on this path).
• A cycle is a sequence of vertices (v1 , . . . , vk ) such that v1 , . . . , vk−1 are all distinct and vk = v1 .
A cycle is odd (even) if it contains an odd (even) number of edges.
1. Algorithm Analysis. Let f (n) := 4n5/3 and g(n) := n5/4 (log n)7 . Prove that g(n) =
O(f (n)). You may use whatever techniques or facts from class you want, but your proof must
be formal and complete.
2. All-Pairs Shortest Paths. Design and analyze a polynomial-time algorithm that takes
in a graph G = (V, E) for all u, v ∈ V computes the length of the shortest u
v path or
determines that no such path exists.
3. (Kleinberg and Tardos, 3.9) There’s a natural intuition that two nodes that are far
apart in a communication network–seperated by many hops–have a more tenuous connection
than two nodes that are close together. There are a number of algorithmic results that are
based to some extent on different ways of making this notion precise. One way involves the
subsceptibility of paths to the deletion of nodes.
Suppose that an n-node graph G = (V, E) contains two nodes s and t such that the distance
between s and t is strictly greater than n/2. Show that there must exist some node v not
equal to either s or t, such that deleting v from G destroys all s
t paths. (In other words,
the graph obtained from G by deleting v contains no s
t paths).
1
Give an algorithm with running time O(n + m) to find such a node v.
4. Best Enemies On The Move. Alice and Bob are very active students at New York
University. They used to be best friends, but now they despise each other. Alice and Bob
can’t stand to be in the same room, or even close to the each other. However, they each take
overloads and are active in several clubs. Is it even possible to avoid each other?
This can be modeled as a graph problem. The input consists of the following.
• a graph G = (V, E).
• an integer k ≤ n.
• start vertices sA , sB ∈ V .
• end vertices tA , tB ∈ V .
In this problem, Alice starts at sA and wants to travel to tA , while Bob starts at sB and
wants to reach tB . At each time step, either Alice or Bob moves along a single edge. (You
can assume that they move separately). At all times, Alice and Bob must be at least k edges
apart.
Design and analyze a polynomial-time algorithm that determines if Alice and Bob can get
where they want to go while maintaining distance.
Hint: It might be helpful to use your solution to problem (2) as a subroutine.
Hint 2: available by request.
5. Extra Credit. In class we saw an algorithm for testing bipartiteness which used BFS to
color the vertices. It should be possible to use DFS to test bipartiteness to color the vertices.
Using pseudocode, give an algorithm that uses DFS to test bipartiteness. Rigorously prove
that your algorithm works.
2