Given a directed graph with positive edge lengths and a specified vertex v in the graph, the "all-pairs" v-constrained shortest path problem" is the problem of computing for each pair of vertices i and j the shortest path from i to j that goes through the vertex v. If no such path exists, the answer is . Describe an algorithm that takes a graph G= (V; E) and vertex v as input parameters and computes values L(i; j) that represent the length of v-constrained shortest path from i to j for all . Prove your algorithm correct. Your algorithm should have a running time in
plzzzzzzzzz Upvote...
Algorithm is very simple, we have to find the shortest path from all the vertex to vertex v and then shortest path from vertex v to every other vertex. So then in order to get shortest path from say v1 to v2, we will use shortest path from v1 to v and then combine shortest path from v to v2 to get the entire path.
Below is the algorithm we follow:-
1. In order to get shortest path from vertex v to every other vertices, perform the Dijkstra algorithm with vertex v as the source vertex.
2. In order to get shortest path from every vertex to vertex v, reverse the direction of all the edges in the graph G to make it graph G'
3. Now compute shortest path from vertex v to every vertex in graph G' such that by reversing all the edges in shortest path tree, we will get the shortest path from every vertex to vertex v in the original graph.
4. Thus shortest path from v1 to v2 i.e. L(v1,v2) = L(v1,v) + L(v,v2).
5. Return
So in the above algorithm we run Dijkstra algorithm 2 times which run in O(E log V) and we modify the edges of the graph in O(E) time, and then finally computed shortest path between every pair of vertex in O(|V|2) time.
So total complexity = O(|V|2)
Please comment for any clarification.
Given a directed graph with positive edge lengths and a specified vertex v in the graph,...
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...
1. Consider a directed graph with distinct and non-negative edge lengths and a source vertex s. Fix a destination vertex t, and assume that the graph contains at least one s-t path. Which of the following statements are true? [Check all that apply.] ( )The shortest (i.e., minimum-length) s-t path might have as many as n−1 edges, where n is the number of vertices. ( )There is a shortest s-t path with no repeated vertices (i.e., a "simple" or "loopless"...
Say that we have an undirected graph G(V, E) and a pair of vertices s, t and a vertex v that we call a a desired middle vertex . We wish to find out if there exists a simple path (every vertex appears at most once) from s to t that goes via v. Create a flow network by making v a source. Add a new vertex Z as a sink. Join s, t with two directed edges of capacity...
Viterbi algorithm We can use dynamic programming on a directed graph G = (V, E) for speech recognition. Each edge (u, v) in E is labeled with a sound s(u, v) from a finite set S of sounds. The labeled graph is a formal model of a person speaking a restricted language. Each path in the graph starting from a distinguished vertex v0 in V corresponds to a possible sequence of sounds produced by the model. The label of a...
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...
10. You are given a directed graph G(V, E) where every vertex vi E V is associated with a weight wi> 0. The length of a path is the sum of weights of all vertices along this path. Given s,t e V, suggest an O((n+ m) log n) time algorithm for finding the shortest path m s toO As usual, n = IVI and m = IEI.
Algorithm Question 5. Below is a graph with edge lengths. Apply Dijkstra's algorithm to find the shortest paths, starting at vertex A, to all other vertices. Write down the sequence in which the edges are chosen, breaking ties by using vertices at the same length in alphabetic orde. 3 Ga 2 5. Below is a graph with edge lengths. Apply Dijkstra's algorithm to find the shortest paths, starting at vertex A, to all other vertices. Write down the sequence in...
For a directed graph the in-degree of a vertex is the number of edges it has coming in to it, and the out- degree is the number of edges it has coming out. (a) Let G[i,j] be the adjacency matrix representation of a directed graph, write pseudocode (in the same detail as the text book) to compute the in-degree and out-degree of every vertex in the Page 1 of 2 CSC 375 Homework 3 Spring 2020 directed graph. Store results...
5. The in-degree of a vertex in a directed graph is the number of edges directed into it. Here is an algorithm for labeling each vertex with its in-degree, given an adjacency-list representation of the graph. for each vertex i: i.indegree = 0 for each vertex i: for each neighbor j of i: j.indegree = j.indegree + 1 Label each line with a big-bound on the time spent at the line over the entire run on the graph. Assume that...
Input a simple undirected weighted graph G with non-negative edge weights (represented by w), and a source node v of G. Output: TDB. D: a vector indexed by the vertices of G. Q: priority queue containing the vertices of G using D[] as key D[v]=0; for (all vertex ut-v) [D[u]-infinity:) while not Q. empty() 11 Q is not empty fu - Q.removein(); // retrieve a vertex of Q with min D value for (all vertex : adjacent to u such...