Algorithm 2017 Spring
Homework 4
範圍:Chapter 22~ Chapter 24
1. (20pts) Given the following undirected graph.
Please use the Depth-First-Search algorithm to show the
timestamp (discovery time and finish time) starting from vertex s
of each vertex on it.
2. (20pts) Find a feasible solution or determine that no feasible
solution exists for the following system of difference constraints
x1 − x2 ≤ 4, x1 − x5 ≤ 5, x2 − x4 ≤ −6, x3 − x2 ≤ 1,
x4 − x1 ≤ 3, x4 − x3 ≤ 5, x4 − x5 ≤ 10, x5 − x3 ≤ −7,
x5 − x4 ≤ −8
3. Consider the single-source shortest-paths problem. The execution
process of Dijkstra’s algorithm can be decomposed into V−1
stages. At each stage, the algorithm finds a shortest path from the
source to a vertex.
(a) (10pts) Describe such a process clearly on the following
di-graph with vertex a as the source.
(b) (10pts) Under what condition Dijkstra’s algorithm will not
work? Given an example to explain your answer.
4. (20pts) Run DAG-SHORTEST-PATHS step by step on the
directed graph of the figure, using vertex s as the source.
5. (20pts) Give an algorithm (or pseudocode) that determines
whether or not a given undirected graph G = (V ,E) contains a
cycle. Your algorithm should run in O(V) time, independent of |E|.
Please explain your answer.