
(Practice) HW 4
•Give an example of a directed graph G= (V , E), a source vertex s∈V,
and a set of tree edges Eπ⊆Esuch that for each vertex v∈V, the unique
path in the graph (V, E π) from sto vis a shortest path in G, yet the set
of edges Eπcannot be produced by running BFS on G, no matter how
the vertices are ordered in each adjacency list.
•There are two types of professional wrestlers:”good guys” and ”bad guys”.
Between any pair of professional wrestlers, there may or may not be a ri-
valry. Suppose we have nprofessional wrestlers and we have a list of rpairs
of wrestlers for which there are rivalries. Give O(n+r)-time algorithm
that determines whether it is possible to designate some of wrestlers as
good guys and the remainder as bad guys such that each rivalry is between
a good guy and bad guy. If it is possible to perform such a designation,
your algorithm should produce it.
•Show that a DFS of a undirected graph Gcan be used to identify the
connected components of G, and that the depth-first forest contains as
many trees as Ghas connected components. More precisely, show how to
modify DFS so that each vertex vis assigned integer label cc[v] between
1 and k, where kis number of connected components of G, such that
cc[u] = cc[v] if and only if uand vare in the same connected component.
•Design an algorithm that given a directed graph G= (V , E) and a distin-
guished vertex s∈V, determines for each v∈Vthe shortest path from s
to v. Your algorithm must run in time O(n+e).
•Aforest is a graph composed of zero or more disconnected trees. Design
an algorithm that, given a graph Gwith nnodes, determines whether G
is a forest in time O(n).
•The out-degree of a vertex vin a graph is the number of edges directed out
of v. The out-degree of a graph is the largest out-degree of its vertices.
Devise a backtracking algorithm that, given a directed graph Gof out-
degree ddetermines whether Ghas a Hamiltonian cycle in time O(dn).
•Problem 4 (page 325 of the textbook)
•Problems 9-11 (Page 337 of the textbook)
•Problem 3 (Page 375 of the textbook)
•Problems 14-17 (Pages 532-533 of the textbook)
1