Question

You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s and a target node t. Design a linear ti

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Single source shortest distances in O(V+E) time for DAG (Directed Acyclic Graph). The idea is to use Topological Sorting.

Algorithm :

1. Initialize dist[] = {INF, INF, ….} and dist[s] = 0 where s is the source vertex.
2. Create a toplogical order of all vertices.
3. Do following for every vertex u in topological order.
Do following for every adjacent vertex v of u

if (dist[v] > dist[u] + weight(u, v))

dist[v] = dist[u] + weight(u, v)

Time Complexity: Time complexity of topological sorting is O(V+E). After finding topological order, the algorithm process all vertices and for every vertex, it runs a loop for all adjacent vertices. Total adjacent vertices in a graph is O(E). So the inner loop runs O(V+E) times. Therefore, overall time complexity of this algorithm is O(V+E).

Add a comment
Know the answer?
Add Answer to:
You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in...

    Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in the graph. Describe an O(n+m) algorithm that computes the number of paths from s to t . (Hint: start by topologically ordering G.)

  • Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph...

    Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph presented in adjacency list representation, where the vertices are labelled with numbers in the set {1, . . . , n}, and where (i, j) is and edge inplies i < j. Suppose also that each vertex has a positive value vi, 1 ≤ i ≤ n. Define the value of a path as the sum of the values of the vertices belonging to...

  • NAME . You are given a strongly connected directed graph G (V, E) with positive edge...

    NAME . You are given a strongly connected directed graph G (V, E) with positive edge weights along with a particular node vo E V. Give an efficient algorithm for finding shortest paths between all pairs of nodes, with the one restriction that these paths must all pass through v (8 points)

  • Given an unweighted directed graph G, write a program that counts and prints all simple paths...

    Given an unweighted directed graph G, write a program that counts and prints all simple paths from a given ‘s’ to a given ‘d’. Assume the graph G is represented using adjacent matrix. Using Java Language

  • Suppose we are given a directed acyclic graph G with a unique source and a unique...

    Suppose we are given a directed acyclic graph G with a unique source and a unique sink t. A vertex v ¢ {s,t} is called an (s,t)-cut vertex if every path from s to t passes through v, or equivalently, if deleting v makes t unreachable from s. Describe and analyze an algorithm to find every (s, t)-cut vertex in G t

  • Consider a directed acyclic graph G = (V, E) without edge lengths and a start vertex...

    Consider a directed acyclic graph G = (V, E) without edge lengths and a start vertex s E V. (Recall, the length of a path in an graph without edge lengths is given by the number of edges on that path). Someone claims that the following greedy algorithm will always find longest path in the graph G starting from s. path = [8] Ucurrent = s topologically sort the vertices V of G. forall v EV in topological order do...

  • Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the gr...

    This question needs to be done using pseudocode (not any particular programming language). Thanks Consider an unweighted, undirected graph G = 〈V, E). The neighbourhood of a node u E V in the graph is the set of all nodes that are adjacent (or directly connected) to v. Subsequently, we can define the neighbourhood degree of the node v as the sum of the degrees of all its neighbours (those nodes that are directly connects to v) (a) Design an...

  • Consider the width search algorithm from a start node s. The diameter of an undirected, contiguous...

    Consider the width search algorithm from a start node s. The diameter of an undirected, contiguous Graph G = (V, E) is defined as the maximum over all node pairs v, w ∈ V of the length of the shortest path from v to w. We assume that each edge has the length of 1. Specify an extension of the width search algorithm in pseudo code that has the diameter of an undirected graph G = (V, E). First explain...

  • 3. Given the graph G shown, we find the shortest paths from node S using the...

    3. Given the graph G shown, we find the shortest paths from node S using the Bellman-Ford algorithm. How many iterations does it take before the algorithm converges to the solution? 4 A 1 -2 10 S -9 E 1 10 -8 B 2

  • 1. Given a graph G = (V, E). a) Design an algorithm to print all the...

    1. Given a graph G = (V, E). a) Design an algorithm to print all the shortest path from a starting node s to all other nodes b) Implement your proposed algorithm above in your preferred programming languages. You can choose to represent the edges in such graph by either adjacency matrix or adjacency list.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT