All-Pairs Shortest Paths: Suppose that we want instead to
compute shortest paths between all pairs of vertices.
We could do this applying either Dijkstra or Bellman-Ford using
every vertex as a source, but
today we will consider an alternative approach, which is based on
dynamic programming.
Let G = (V, E) be a directed graph with edge weights. For each edge
(u, v) E, let w(u, v)
denote its weight. The cost of a path is the sum of its edge
weights, and the distance between
two vertices, denoted δ(u, v), minimum cost of any path between u
and v. As in Bellman-
Ford, we allow negative cost edges, but no negative-cost cycles.
(Recall that negative-cost
cycles imply that shortest paths are not defined.)
The algorithm that we will present is called the Floyd-Warshall
algorithm. It runs in O(n
3
)
time, where n = |V |. It dates back to the early 1960’s. The
algorithm can be adapted for use
in a number of related applications as well.
Transitive
Closure: You are given a binary relation
R on a set X, by which we mean that
R is a subset of ordered pairs (x, y) ⊆ X × X. A relation is said
to be transitive if for
any x, y, z ∈ X, if (x, y) ∈ R and (y, z) ∈ R then (x, z) ∈ R. The
transitive closure of
R, denoted R∗
is the smallest extension of R that is transitive.
We can think of (X, R) as a directed graph, where X are the
vertices and the pairs of R
are edges. The transitive closure of R is effectively the same as
the reachability relation
in this graph, that is, (x, y) ∈ R∗
if and only if there exists a path from x to y in R.
The Floyd-Warshall algorithm can be modified to compute the
transitive closure in time
O(n
3
), where n = |X|.
It seems that for sparse graphs with weighted edges Dijkstra’s algorithm it more useful, because it runs faster than Floyd-Warshall one. For other graphs it is better to use Floyd-Warshall to compute the shortest path., because Dijkstra’s one would fail here.
Problem 2: As we discussed in class, one can use an algorithm for computing all-pairs shortest...
Help. I need to write a small program that executes the following graph algorithms in any language: 1. All-Pairs Shortest Path (Floyd-Warshall). It must ask for the vertices and edges for the user to enter them. As an output, deploy the resulting matrix. This will be done only for directed graphs. 2. Kruskal or Prim algorithm whatever you want to do. It must ask for a graph and present it at the end. The minimum coating tree that results from...
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...
Consider the problem of finding the shortest paths in a weighted directed graph using Dijkstra's algorithm. Denote the set of vertices as V, the number of vertices as |V|, the set of edges as E, and the number of edges as |E|. Answer the following questions.Below is a pseudo-code of the algorithm that computes the length c[v] of the shortest path from the start node s to each node v. Answer code to fill in the blank _______ .
2. Apply Dijkstra’s algorithm as discussed in class to solve the single-source shortest-paths problem for the following graph. Consider node a to be the source. (10 points) a. Show the completed table. b. State the shortest path from A to J and state its length. c. State the shortest path from A to K and state its length. d. State the shortest path from A to L and state its length. 3 5 6 4 3 2 1 2. d...
5. Apply Dijkstra's algorithm as discussed in class to solve the single-source shortest-paths problem for the following graph. Consider node A to be the source. (20 points) a. Show the completed table. b. State the shortest path from A to E and state its length. C. State the shortest path from A to F and state its length. d. State the shortest path from A to G and state its length. A 12 9 B 17 8 7 10 8...
Apply Dijkstra's algorithm as discussed in class to solve the single-source shortest-paths problem for the following graph. Consider node A to be the source. (20 points) a. Show the completed table. b. State the shortest path from A to E and state its length. State the shortest path from A to F A 9 and state its length. d. State the shortest path from A to G 17 and state its length. 7 C. 12 B 8 10 D 8...
1. Warshall's Algorithm To which other algorithm from our course is Wasrhall's Transitive Closure algorithm most structurally similar? A) Dijkstra B) Floyd C) Kadane D) Karatsuba E) Kruskal F) Prim G) Strassen 2. Powers of Adjacency Matrix Which is true of an Adjacency Matrix of a directed graph raised to the k-th power (A^k) A) A^k [i][j] = 1 if there is an edge of length k from vertex i to vertex j B) A^k [i][j] = 1 if there...
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...
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...