RevG(A[1..V])
initialize B[1..V], same vertex names, empty linked lists
for i <- 1 through V
for each out-neighbor e in A[i]
add i to the beginning of the linked-list B[e]
return B[1..V]
You are asked to explain why \(X\) implies \(Y\). “Begging the question” is an argument of the following form:
\(X\) implies \(Y\) because if \(X\) is true, then \(Y\) must be true.
IsSemiConnected(G):
compute scc(G)
let v_1..v_n be a topological sort of scc(G)
for i in 1..n
if v_i v_[i+1] is not an edge of scc(G)
return False
return True
\(a.\) The graph scc(G)
is a DAG, meaning that you can’t loop back to an earlier component in the topological order, so there is not a path from v[i+1] to v[i] in scc(G). So if there also isn’t an edge from v[i] to v[i+1], there is no connection between v[i] and v[i+1]. This means that if u is a vertex of G that lies in the component v[i] and v is a vertex in G that lies in v[i+1], there can be no path from u to v, and no path from v to u. So the graph is not semi-connected.
IsSemiConnected(G):
compute scc(G)
let v_1..v_n be a topological sort of scc(G)
for i in 1..n
if v_i v_[i+1] is not an edge of scc(G)
return False
return True
\(b.\) The function can only return True
if we’ve gone through all the components and all of them had an edge to the component after them. Let u
and v
be any two vertices of G
. If u
and v
are in the same component, then there is a path between them because the component is strongly connected. Suppose u
and v
are in different components. If u.post
> v.post
, then u
’s component comes before v
’s in topological order, so there is a path from u
’s component to v
’s component in scc(G)
. Therefore there is a path from u
to v
in G
. Similarly, if v.post
> u.post
, there is a path from v
to u
in G
.
IsSemiConnected(G):
compute scc(G)
let v_1..v_n be a topological sort of scc(G)
for i in 1..n
if v_i v_[i+1] is not an edge of scc(G)
return False
return True
compute scc(G)
is \(O(V+E)\).for
-loop requires \(O(V_\text{scc} + E_\text{scc} )\)Table #1 | Table #2 | Table #3 | Table #4 | Table #5 | Table #6 | Table #7 |
---|---|---|---|---|---|---|
John | Andrew | Jordan | James | Josiah | Trevor | Isaac |
Nathan | Blake | Grace | Bri | Jack | Levi | Drake |
Graham | Kevin | Kristen | Talia | Claire | Logan | Ethan |