HW3
HW3
• Please type your solutions using LATEX or any other software. Handwritten solutions will not
be accepted for this assignment.
• Your algorithms must be in plain English & mathematical expressions. Pseudo-code without
sufficient explanation will receive no credit.
• If we ask for an algorithm with a specific runtime, we will only accept answers with that
specific runtime, even if a faster solution exists. If we ask for an “efficient” algorithm, we
will not accept answers if a faster algorithm than the one provided exists.
• Unless a question explicitly states that no work is required to be shown, you must provide
an explanation or justification for your answer.
1.) Reference this graph for both parts of this problem:
F J
H C
A B
I G
E D
Part A
For this part, in the event of a tie, choose the node that is alphabetically first.
a.) Run DFS on this graph and list the pre and post labels of each vertex. Show your work; we
do not require a specific format but we want to see that some work was performed.
Part B
For this part, we run the SCC algorithm on the above graph. When running DFS on the re-
verse graph, use the alphabetical order of vertices.
a.) Write the strongly connected components in the order you found them. Show your work; we
do not require a specific format but we want to see that some work was performed.
b.) List all the sink components and all the source components. Provide a short justification.
c.) Give the minimum number of edges that must be added to the graph above to make it
strongly connected. Justify your answer.
Solution: [Write your answer here]
d.) Topologically sort the metagraph using the technique described in class. List the components
in that order. No work is required.
a) The vertex with the smallest post-order number in a depth-first search must belong to a sink
strongly connected component (sink meta-node) of the graph.
b) In a directed acyclic graph, if a vertex is a source, then it must have the largest post-order
number in a depth-first search.
c) The meta-graph of a directed acyclic graph is the same as the original graph.
d) If a back edge is found during a depth-first search traversal, the graph contains a cycle.
Your task is to determine if you can split all the guests into exactly two tables in such a way that
no conflicting pair of guests ends up at the same table. Concretely, you want to see if there is
a way to label each vertex (guest) as belonging to one of two groups—think of them as “Table
A” and “Table B”—so that whenever two vertices are connected by an edge, they are assigned to
different tables.
Design an algorithm that checks whether such a two-table arrangement exists and, if it does,
outputs the arrangement. If no valid split is possible, the algorithm should report that the guests
cannot be separated without causing a conflict at one of the tables (more tables will be needed).
1. Describe your algorithm to a degree where someone could implement it if given your answer.
2. Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs).
(a.) Describe your algorithms to a degree where someone could implement it if given your answer.
(b.) Argue why your algorithm is correct (given any input, why does your algorithm produce the
correct outputs).
(d.) Now with a directed graph Gd = (Vd , Ed ), give an efficient algorithm that determines whether
or not there is a vertex sd ∈ Vd from which all other vertices are reachable. Describe just the
algorithm in 4-5 sentences (no correctness or runtime).