Q1: Here we consider finding the length of the shortest path between all pairs of nodes in an undirected, weighted graph G. For simplicity, assume that the n nodes are labeled 1; 2; : : : ; n, that the weight wij of any edge e = (i; j) is positive and that there is an edge between every pair of nodes. In this question, the goal is to solve this via dynamic programming. Note that the algorithm you will develop is not the Bellman-Ford algorithm.
1.1: Let D[i; j; k] be the length of the shortest path from node i to node j in which the intermediate nodes on the path are all in the set f1; 2; : : : ; kg. Note that D[i; i; k] = 0 for all i and
k and that D[i; j; 0] = wij for all i 6= j. A formula for D[i; j; k] with two missing arguments is:
D[i; j; k] = min(D[i; j; k - 1];D[i; k; k - 1] + D[k; j; k - 1]
when k >= 0. Fill in the two missing arguments.
1.2: Write pseudo-code for an efficient dynamic programming (using the above formula) to compute the shortest path between every pair of nodes. Hint: You need to specify how each D[i; j; k] is computed, the order in which they are computed, and the final output.
1.3: What is the running time of your algorithm? Justify your answer?
1.4: What is the number of edge-disjoint paths between node 1 and node 2 in G? Your answer should be a function of n. Recall that G had an undirected edge between every pair of nodes.
Question 1) D[i; j; k] = min(D[i; j; k - 1]; D[i; k; k - 1] + D[k; j; k - 1]; D[i; j; k]; Wij)
Question 2)
main:
for k = [1; n]
for i = [1; n]
for j = [1; n]
D[i,j,k] = INF
for k = [1; n]
for i = [1; n]
for j = [1; n]
D[i, j, k] = min(D[i,j,k],
D[i,j,k-1],D[i,k,k-1]+D[k,j,k-1],W[i,j])
Question 3)
This algorithm needs to fill N*N*N table. Each entry is calculated once and each calculation can be done in O(1). So time complexity for this algorithm is O(N^3)
Question 4)
f(N) = N-1
Let's say starting node is X and ending node is Y. Each of them
have N-1 different edges connected to them so answer can be at most
N-1, we can not get N or more paths. Now let's prove that N-1
different paths exists. Let's say that Z is node in N different
from X and Y, there are N-2 such nodes. As there is edge between
any two nodes we now that X is connected to Z and Z is connected to
Y, so we have path X-Z-Y. As Z has N-2 different values we have N-2
different paths which have different edges in them. Also X is
connected with Y and X-Y path exists and in total we Have N-1
paths.
Comment down for any queries
please give a thumbs up
Q1: Here we consider finding the length of the shortest path between all pairs of nodes...
9. In the graph below (A) Determine the shortest path from a to ALL other nodes using Dijkstra's Shortest Path Algorithm, The answers must be in the following form: For each node, give the shortest path from a to that node (that is, list the nodes in the path). Also for each path give the length of the path. (B) ON THIS SHEET OF PAPER SHOWING A TRACE OF DIJKSTRA'S ALGORITHM ON THE GRAPH BELOW AS IDID IN CLASS FOR FULL CREDIT YOU MUST LABEL...
1.What does a file index do? Why do we need a file index? 2.Modified All-Pairs Shortest Paths Problem This is the All-Pairs Shortest Paths problem with the following modification. Let n be the number of nodes in input graph. There are additional inputs k1, d in [1..n]. For every path that starts at, or ends at, or passes through node k1,distance d is added to the total distance of the path. Calculate shortest distances for all pairs of nodes (as in...
Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path problem for unweighted undirected graphs. The cost of a path in this setting is the number of edges in the path. The algorithm UNWEIGHTEDAPSP takes the following input and output: UNWEİGHTEDA PSP Input: An unweighted undirected graph G Output: The costs of the shortest paths between each pair of vertices fu, v) For example, consider the following graph G. The output of...
Identify the steps of an algorithm that uses the concept of interior vertices in a path to find the length of the shortest path between two vertices in a directed graph, if such a path exists. (Check all that apply.) A. procedure Warshall (MR : n × n zero–one matrix)procedure Warshall (MR : n × n zero–one matrix) B. for i : = 1 to n for j : = 1 to n if mij = 0 then mij =...
4. Given a network of 8 nodes and the distance between each node as shown in Figure 1: 4 1 7 0 4 4 6 6 Figure 1: Network graph of 8 nodes a) Find the shortest path tree of node 1 to all the other nodes (node 0, 2, 3, 4, 5, 6 and 7) using Dijkstra's algorithm. b) Design the Matlab code to implement Dijkstra's algorithm 4. Given a network of 8 nodes and the distance between each...
please help Programming: Undirected Graphs 10. Run the BFS algorithm on this graph to compute the shortest paths between 0 and every other node. For reference, the BFS algorithm is shown on the next page. Use the adjacency list above for the order of the nodes explored and follow the trace format shown before. Your answer must include the values of v, queue, and edge To, as they update. [20 point s 0 3, 1 10, 4, 3, 2 21.5...
We now consider undirected graphs. Recall that such a graph is • connected iff for all pairs of nodes u, w, there is a path of edges between u and w; • acyclic iff for all pairs of nodes u, w, whenever there is an edge between u and w then there is no path Given an acyclic undirected graph G with n nodes (where n ≥ 1) and a edges, your task is to prove that a ≤ n...
PYTHON ONLY Implement the Dijkstra’s Shortest path algorithm in Python. A graph with 10 nodes (Node 0 to node 9) must be implemented. You are supposed to denote the distance of the edges via an adjacency matrix (You can assume the edge weights are either 0 or a positive value). The adjacency matrix is supposed to be a 2-D array and it is to be inputted to the graph. Remember that the adjacency list denotes the edge values for the...
In the network below, let us suppose that the link between nodes ‘k’ and ‘m’ has been failed. Using your knowledge of link-state routing, calculate the shortest path from node ‘i’ to node ‘j’ before failure and after failure. Also, mention the costs from node ‘i’ to node ‘j’ before failure and after failure. [Hint = For example, the cost from node ‘i’ to node ‘r’ is 1 and the path is i-r] m 4 n 5 r 1
Design and implement Dijkstra’s algorithm to compute all-pair shortest paths in any given graph using An adjacency matrix using a one-dimensional array for storing only the elements of the lower triangle in the adjacency matrix.[Program in C language] The input to program must be connected, undirected, and weighted graphs. The programs must be able to find shortest paths on two types of connected, undirected, and weighted graphs: complete graph (a graph with a link between every pair of nodes) and...