Solved

# Floyd algorith to get shortest path between two vertices

Posted on 2004-10-26
640 Views
I am trying to implement floyd algorith to find shortest path ..cna any one help me...
0
Question by:prashanth_gurijala

LVL 11

Expert Comment

No one will code for you but if you show what you have done .. others may try to help you

googling "floyd algorithm " gave me the folowing

maybe you can modify the above to suit your needs
0

LVL 55

Expert Comment

0

LVL 9

Accepted Solution

hi,

floyd on adjacent matrix W for the graph
floyd(W)
{
n is the number of rows in W;
D(0)=W;
for k = 1 to n
for i = 1 to n
for j = 1 to n
{
D(k)[i][j]=MIN(D(k-1)[i][j], D(k-1)[i][k] + D(k-1)[k][j]);
}
}

means for all i and j, I want to know the minimum path between i and j that k participate in the path,
so for all k, i replace D[i][j] with the min of D[i][j] and D[i][k]+D[k][j], that means, if the path between i -> k, and then k ->j is smaller than the path i->j  that doesn't use k in the path, i use this minimum.

note that you can use one D matrix for above operation.

have a good programming day.
0

## Featured Post

Some Windows API functions expect you to provide a pointer to a CALLBACK function that the system will need to call as part of the operation.  Such API functions as SetTimer, timeSetEvent, CreateThread, EnumWindows, LineDDA, even window message hand…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.