Question

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 in G. You can assume that G is given to you in the adjacency-list representation.

Homework Answers

Answer #1

Since the Graph is a DAG we can Topologically sort it.

and then add the value of nodes 'v' that do not have incoming edge to the nodes having edge from v.

Algorithm:

Topologically Sort G   

repeat until |G|>0

      find a vertex v having no incoming edge

      add its value to all vertices 'u' present in the adjacency list of v

     remove v

Time complexity : Topological sort takes O(m+n)

since the graph is already topologically sorted, finding vertex with no incoming edge takes O(1) time (it is the one with largest finishing time)

each vertex is removed once and same is with the edge so removal of verteices and edges take O(m+n) time. So total time taken is O(m+n)

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
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.)
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.
Suppose that we generate a random graph G = (V, E) on the vertex set V...
Suppose that we generate a random graph G = (V, E) on the vertex set V = {1, 2, . . . , n} in the following way. For each pair of vertices i, j ∈ V with i < j, we flip a fair coin, and we include the edge i−j in E if and only if the coin comes up heads. How many edges should we expect G to contain? How many cycles of length 3 should we...
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number...
Problem 2. Consider a graph G = (V,E) where |V|=n. 2(a) What is the total number of possible paths of length k ≥ 0 in G from a given starting vertex s and ending vertex t? Hint: a path of length k is a sequence of k + 1 vertices without duplicates. 2(b) What is the total number of possible paths of any length in G from a given starting vertex s and ending vertex t? 2(c) What is the...
Let G be a graph where every vertex has odd degree, and G has a perfect...
Let G be a graph where every vertex has odd degree, and G has a perfect matching. Prove that if M is a perfect matching of G, then every bridge of G is in M. The Proof for this question already on Chegg is wrong
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
Labor Relations- Chapter 5- G o v e r n m e n t s ,...
Labor Relations- Chapter 5- G o v e r n m e n t s , L a b o u r R e l a t i o n s B o a r d s , a n d O t h e r P a r t i e s Case Study- Quality Inn & Suites Brantford v. UFCW Local 175 In January 2012 the Ontario Labour Relations Board was asked to consider an application for the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT