Question

Design an algorithm that for a given DAG G = (V, E) checks/recognizes if G is...

Design an algorithm that for a given DAG G = (V, E) checks/recognizes if G is semi-connected in time O(|V | + |E|). A directed graph G = (V, E) is called semi-connected if and only if for every two vertices u, v ∈ V there is a directed path from u to v or from v to u

Homework Answers

Answer #1

A DAG is semi connected in a topological sort, for each i, there is an edge (vi,vi+1)

Complexity of Algorithm: O(|v|+|e|)

Given a DAG with topological sort v1,v2,...,vn:

If there is no edge (vi,vi+1) for some i, then there is also no path (vi+1,vi) (because it's a topological sort of a DAG), and the graph is not semi connected.

If for every i there is an edge (vi,vi+1), then for each i,j (i < j) there is a path vi->vi+1->...->vj-1->vj, and the graph is semi connected.

From this we can get the algorithm:

  1. Find Maximal SCCs in the graph
  2. Build the SCC graph G'=(U,E') such that U is a set of SCCs. E'= {(V1,V2) | there is v1 in V1 and v2 in V2 such that (v1,v2) is in E)
  3. Do topological sort on G'
  4. If there exists more than one topological order of graph G , then graph is not semi connected. Otherwise the graph is connected.

Assume there is no root. Define #(v) = |{u | there is a path from v to u}| (number of nodes that has a path from v to them).
Choose a such that #(a) = max{#(v) | for all v}.
a is not a root, so there is some node u that has no path from a to it. Since graph is semi connected, it means there is a path u->...->a. But that means #(u) >= #(a) + 1 (all nodes reachable from a and also u).
Contradiction to maximality of #(a), thus there is a root.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You are given a directed acyclic graph G(V,E), where each vertex v that has in-degree 0...
You are given a directed acyclic graph G(V,E), where each vertex v that has in-degree 0 has a value value(v) associated with it. For every other vertex u in V, define Pred(u) to be the set of vertices that have incoming edges to u. We now define value(u) = ?v∈P red(u) value(v). Design an O(n + m) time algorithm to compute value(u) for all vertices u where n denotes the number of vertices and m denotes the number of edges...
Given a directed acyclic graph G= (V,E), vertex s∈V, design a dynamic programming algorithm to compute...
Given a directed acyclic graph G= (V,E), vertex s∈V, design a dynamic programming algorithm to compute the number of distinct paths from s to v for any v∈V. 1. Define subproblems 2. Write recursion 3. Give the pseudo-code 4. Analyze the running time.
Let G = (V,E) be a graph with n vertices and e edges. Show that the...
Let G = (V,E) be a graph with n vertices and e edges. Show that the following statements are equivalent: 1. G is a tree 2. G is connected and n = e + 1 3. G has no cycles and n = e + 1 4. If u and v are vertices in G, then there exists a unique path connecting u and v.
we consider a graph G= (V, E), with n=|V| and m=|E|. Describe an O(n+m) time algorithm...
we consider a graph G= (V, E), with n=|V| and m=|E|. Describe an O(n+m) time algorithm to find such a vertex w. Hint: a depth-first search from u might be helpful.
A spanning tree of connected graph G = (V, E) is an acyclic connected subgraph (V,...
A spanning tree of connected graph G = (V, E) is an acyclic connected subgraph (V, E0 ) with the same vertices as G. Show that every connected graph G = (V, E) contains a spanning tree. (It is the connected subgraph (V, E0 ) with the smallest number of edges.)
A triangle in a graph G=(V,E)is a 3-cycle; i.e. a set of three vertices {u,v,w}such that...
A triangle in a graph G=(V,E)is a 3-cycle; i.e. a set of three vertices {u,v,w}such that (u,v),(v,w),(u,w)∈E . Present an O(n3) Algortihm that will list all triangles.
Let u and v be distinct vertices in a graph G. Prove that there is a...
Let u and v be distinct vertices in a graph G. Prove that there is a walk from ? to ? if and only if there is a path from ? to ?.
Discrete math problem: The length of a path between vertices u and v is the sum...
Discrete math problem: The length of a path between vertices u and v is the sum of the weights of its edges. A path between vertices u and v is called a shortest path if and only if it has the minimum length among all paths from u to v. Is a shortest path between two vertices in a weighted graph unique if the weights of edges are distinct? Give a proof.
Consider a minimum spanning tree for a weighted graph G= (V, E)and a new edge e,...
Consider a minimum spanning tree for a weighted graph G= (V, E)and a new edge e, connecting two existing nodes in V. Explain how to find a minimum spanning tree of the new graph in O(n)time, where n is the number of nodes in the graph. Prove correctness of the algorithm and justify the running time
Exercise 10.5.4: Edge connectivity between two vertices. Two vertices v and w in a graph G...
Exercise 10.5.4: Edge connectivity between two vertices. Two vertices v and w in a graph G are said to be 2-edge-connected if the removal of any edge in the graph leaves v and w in the same connected component. (a) Prove that G is 2-edge-connected if every pair of vertices in G are 2-edge-connected.