All pairs shortest paths algorithm, Data Structure & Algorithms

Assignment Help:

In the last section, we discussed regarding shortest path algorithm that starts with a single source and determines shortest path to all vertices in the graph. In this section, we will discuss the problem of finding shortest path among all pairs of vertices in a graph. This problem is helpful in finding distance among all pairs of cities in a road atlas. All pairs shortest paths problem is mother of all of the shortest paths problems.

In this algorithm, we shall represent the graph through adjacency matrix.

The weight of an edge Cij in an adjacency matrix representation of any directed graph is represented as follows

1625_All Pairs Shortest Paths Algorithm.png

Given directed graph G = (V, E), where each edge (v, w) contain a non-negative cost C(v , w), for all of the pairs of vertices (v, w) to determine the lowest cost path from v to w.

The All pairs shortest paths problem can be considered as a generalisation of single- source-shortest-path problem, using Dijkstra's algorithm by varying the source node amongst all the nodes in the graph. If negative edge(s) is allowed, then we can't employ Dijkstra's algorithm.

In this segment we will employ a recursive solution to all pair shortest paths problem known as Floyd-Warshall algorithm, which runs in O(n3) time.

This algorithm is depends on the following principle. For graph G let V = {1, 2,3,...,n}.Let us assume a sub set of the vertices {1, 2, 3, .....,k. For any pair of vertices which belong to V, assume all paths from i to j whose intermediate vertices are from {1, 2, 3, ....k}. This algorithm will exploit the relationship among path p and shortest path from i to j whose intermediate vertices are from {1, 2, 3, ....k-1} with the given two possibilities:

1.   If k is not any intermediate vertex in the path p, then all of the intermediate vertices of the path p are in {1, 2, 3, ....,k-1}. Therefore, shortest path from i to j along intermediate vertices in {1, 2, 3, ....,k-1} is also the shortest path from i to j along vertices in {1, 2, 3, ..., k}.

2.   If k is intermediate vertex of the path p, we break down the path p in path p1 from vertex i to k and path p2 from vertex k to j. So, path p1 is the shortest path from i to k  along with intermediate vertices in {1, 2, 3, ...,k-1}.

Throughout iteration process we determine the shortest path from i to j using only vertices (1, 2,3, ..., k-1} and in the next step, we determine the cost of using the kth vertex as an intermediate step. If this results into lower cost, then we store it.

After n iterations (all possible iterations), we determine the lowest cost path from i to j by using all vertices (if essential).

Notice the following:

Initialize the matrix

 C[i][ j] = ∞ if (i, j) does not associate with E for graph G = (V, E)

 Initially, D[i][j] = C[i][j]

We also term a path matrix P where P[i][j] holds intermediate vertex k on the least cost path from i to j which leads to the shortest path from i to j .


Related Discussions:- All pairs shortest paths algorithm

Create a function to show data structure, Given a number that is represente...

Given a number that is represented in your data structure, you will need a function that prints it out in base 215 in such a way that its contents can be checked for correctness. Y

Data manipulation, perform the following length operation LENGTH("welcome t...

perform the following length operation LENGTH("welcome to ICA")=

Pest control program, PART- Pest Control Program Prepare a Pest Contro...

PART- Pest Control Program Prepare a Pest Control Program for the facility that will address the management of Rodents, Insects and Birds. Your Pest Control Program should

Numerical - algorithm, Q. What is the smallest value of n such that an algo...

Q. What is the smallest value of n such that an algorithm whose running time is 100n2 runs faster than an algorithm whose running time is 2n on the same machine.    A n

Algorithm, what algorithms can i use for the above title in my project desi...

what algorithms can i use for the above title in my project desing and implmentation of road transport booking system

Implement an algorithm to simulate car re-organizing, Design  and implement...

Design  and implement  an algorithm  to simulate car  re-organizing of the train at the railway switching junction. You can only use stacks as the data structure to represent the t

Entity relationship diagram, This question is based on the requirements of ...

This question is based on the requirements of a system to record band bookings at gigs. (A 'gig' is an event at which one or more bands are booked to play). You do not need to know

Program segment for deletion of any element from the queue, Program segment...

Program segment for deletion of any element from the queue delete() { int delvalue = 0; if (front == NULL) printf("Queue Empty"); { delvalue = front->value;

Program on radix sort., Write a program that uses the radix sort to sort 10...

Write a program that uses the radix sort to sort 1000 random digits. Print the data before and after the sort. Each sort bucket should be a linked list. At the end of the sort, the

Adjacency matrix, Q. Give the adjacency matrix for the graph drawn below:  ...

Q. Give the adjacency matrix for the graph drawn below:                                                 Ans: Adjacency matrix for the graph given to us

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd