2

I just want to make sure this would work. Could you find the greatest path using Dijkstra's algorithm? Would you have to initialize the distance to something like -1 first and then change the relax subroutine to check if it's greater?

This is for a problem that will not have any negative weights.

This is actually the problem:

Suppose you are given a diagram of a telephone network, which is a graph G whose vertices represent switches centers, and whose edges represent communication lines between two centers. The edges are marked by their bandwidth of its lowest bandwidth edge. Give an algorithm that, given a diagram and two switches centers a and b, will output the maximum bandwidth of a path between a and b.

Would this work?


EDIT:

I did find this:

Hint: The basic subroutine will be very similar to the subroutine Relax in Dijkstra. Assume that we have an edge (u, v). If min{d[u],w(u, v)} > d[v] then we should update d[v] to min{d[u],w(u, v)} (because the path from a to u and then to v has bandwidth min{d[u],w(u, v)}, which is more than the one we have currently).

Not exactly sure what that's suppose to mean though since all distance are infinity on initialization. So, i don't know how this would work. any clues?

Matt
  • 7,049
  • 7
  • 50
  • 77
  • 1
    The short answer is: no, it wouldn't work. The longest path problem doesn't have the optimal substructure that is assumed by Djikstra's, so Djikstra's will not give you the correct answer. –  Apr 18 '11 at 04:20

6 Answers6

1

You can solve this easily by modifying Dijkstra's to calculate maximum bandwidth to all other vertices.

You do not need to initialize the start vertex to -1.

Algorithm: Maximum Bandwidth(G,a)

Input: A simple undirected weighted graph G with non -ve edge weights, and a distinguished     vertex a of G

Output: A label D[u], for each vertex u of G, such that D[u] is the maximum bandwidth available from a to u.


Initialize empty queue Q;
Start = a;
for each vertex u of G do,
   D[u] = 0;

for all vertices z adjacent to Start do{                              ---- 1

 If D[Start] => D[z] && w(start, z) > D[z] {
    Q.enqueue(z);
    D[z] = min(D[start], D[z]);
  }
}
If Q!=null {
   Start = Q.dequeue;
   Jump to 1

}

else
  finish();

This may not be the most efficient way to calculate the bandwidth, but its what I could think of for now.

Sam
  • 11
  • 1
1

I'm not sure Djikstra's is the way to go. Negative weights do bad, bad things to Djikstra's.

I'm thinking that you could sort by edge weight, and start removing the lowest weight edge (the worst bottleneck), and seeing if the graph is still connected (or at least your start and end points). The point at which the graph is broken is when you know you took out the bottleneck, and you can look at that edge's value to get the bandwidth. (If I'm not mistaken, each iteration takes O(E) time, and you will need O(E) iterations to find the bottleneck edge, so this is an O(E2) algorithm.

Edit: you have to realize that the greatest path isn't necessarily the highest bandwidth: you're looking to maximize the value of min({edges in path}), not sum({edges in path}).

  • @bdares he said there are no negative weights – Trevor Arjeski Apr 18 '11 at 04:03
  • If the original graph has no negative weights, then negating them would make them negative... which is the first thing you think of when using a shortest-path algorithm for finding the longest path. –  Apr 18 '11 at 04:06
  • 1
    You really, really can't. At least, until we prove that P==NP we can't. The longest path problem is NP-complete. –  Apr 18 '11 at 04:13
  • @bdares - interesting. So, would you just keep removing edges and when you find an edge that makes the path incomplete from A to B, then just leave that edge alone and continue to the next until all edges have been iterated through? – Matt Apr 18 '11 at 04:24
  • no... if I'm understanding correctly, the bandwidth is limited by the smallest bandwidth edge in your chosen path. So, you want to maximize this smallest bandwidth edge. So, you continue to remove the "currently smallest" edge until you find out that the currently smallest edge is essential for the connection. Then you stop, because you know you can't increase your bandwidth by using some other edge instead of the currently smallest one. –  Apr 18 '11 at 04:29
  • @bdares - basically find the highest weighted edges with the minimum amount of edges used? – Matt Apr 18 '11 at 04:35
  • The goal is to find the path with the highest bandwidth. The number of edges doesn't matter; what matters is what's the weakest link? The chain can only handle as much as its weakest link; so we keep removing the weakest link until we find out that the weakest link can't be removed. Removing stronger links won't make the chain stronger overall, so we don't care about them, and just focus on making the chain a little stronger by taking out the currently weakest link. –  Apr 18 '11 at 04:47
0

Can you adjust some of the logic in algorithm AllPairsShortestPaths(Floyd-Warshall)? http://www.algorithmist.com/index.php/Floyd-Warshall%27s_Algorithm

Initialize unconnected edges to negative infinity and instead of taking the min of the distances take the max?

0

calculating flow may be more applicable, however flow allows for multiple paths to be used.

Ian
  • 3,500
  • 1
  • 24
  • 25
0

Just invert the edge weights. That is, if the edge weight is d, consider it instead as d^-1. Then do Dijkstra's as normal. Initialize all distances to infinity as normal.

darth happyface
  • 2,687
  • 2
  • 20
  • 15
0

You can use Dijkstra's algorithm to find a single longest path but since you only have two switch centers I don't see why you need to visit each node as in Dijkstra's. There is most likes a more optimal way of going this, such as a branch and bound algorithm.

Trevor Arjeski
  • 2,108
  • 1
  • 24
  • 40