मैं तीनों का अध्ययन कर रहा हूं और मैं नीचे से उनके संदर्भ बता रहा हूं। क्या कोई मुझे बता सकता है कि क्या मैंने उन्हें पर्याप्त रूप से पर्याप्त समझा है या नहीं? धन्यवाद।क्या मैं फ़्लॉइड-वारशॉल, डिजस्ट्रा और बेलमैन-फोर्ड एल्गोरिदम के बीच अंतर के बारे में सही हूं?
डिज्कस्ट्रा एल्गोरिथ्म केवल प्रयोग किया जाता है आप एक ही स्रोत है और आप एक से दूसरे नोड से छोटी से छोटी पथ पता करना चाहते हैं, लेकिन this
फ्लोयड-Warshall एल्गोरिथ्म प्रयोग किया जाता है जब तरह के मामलों में विफल रहता है सभी नोड्स में से कोई भी स्रोत हो सकता है, इसलिए आप किसी भी स्रोत नोड से किसी भी गंतव्य नोड तक पहुंचने के लिए सबसे छोटी दूरी चाहते हैं। यह केवल विफल रहता है जब वहाँ नकारात्मक चक्र
(यह सबसे महत्वपूर्ण है कर रहे हैं। मेरा मतलब है, यह एक मैं कम से कम यकीन है कि के बारे में :)
3.Bellman-फोर्ड है कर रहा हूँ है जब केवल एक स्रोत होता है, तो डिज्क्रस्ट्रा की तरह प्रयोग किया जाता है। यह नकारात्मक वजन को नियंत्रित कर सकता है और इसका काम फ़्लॉइड-वॉर्शल के समान स्रोत के समान है, है ना?
आप देखने के लिए की जरूरत है, इसी एल्गोरिदम हैं (सौजन्य विकिपीडिया):
Bellman- फोर्ड:
procedure BellmanFord(list vertices, list edges, vertex source)
// This implementation takes in a graph, represented as lists of vertices
// and edges, and modifies the vertices so that their distance and
// predecessor attributes store the shortest paths.
// Step 1: initialize graph
for each vertex v in vertices:
if v is source then v.distance := 0
else v.distance := infinity
v.predecessor := null
// Step 2: relax edges repeatedly
for i from 1 to size(vertices)-1:
for each edge uv in edges: // uv is the edge from u to v
u := uv.source
v := uv.destination
if u.distance + uv.weight < v.distance:
v.distance := u.distance + uv.weight
v.predecessor := u
// Step 3: check for negative-weight cycles
for each edge uv in edges:
u := uv.source
v := uv.destination
if u.distance + uv.weight < v.distance:
error "Graph contains a negative-weight cycle"
डिज्कस्ट्रा:
1 function Dijkstra(Graph, source):
2 for each vertex v in Graph: // Initializations
3 dist[v] := infinity ; // Unknown distance function from
4 // source to v
5 previous[v] := undefined ; // Previous node in optimal path
6 // from source
7
8 dist[source] := 0 ; // Distance from source to source
9 Q := the set of all nodes in Graph ; // All nodes in the graph are
10 // unoptimized - thus are in Q
11 while Q is not empty: // The main loop
12 u := vertex in Q with smallest distance in dist[] ; // Start node in first case
13 if dist[u] = infinity:
14 break ; // all remaining vertices are
15 // inaccessible from source
16
17 remove u from Q ;
18 for each neighbor v of u: // where v has not yet been
19 removed from Q.
20 alt := dist[u] + dist_between(u, v) ;
21 if alt < dist[v]: // Relax (u,v,a)
22 dist[v] := alt ;
23 previous[v] := u ;
24 decrease-key v in Q; // Reorder v in the Queue
25 return dist;
फ्लोयड-Warshall:
1 /* Assume a function edgeCost(i,j) which returns the cost of the edge from i to j
2 (infinity if there is none).
3 Also assume that n is the number of vertices and edgeCost(i,i) = 0
4 */
5
6 int path[][];
7 /* A 2-dimensional matrix. At each step in the algorithm, path[i][j] is the shortest path
8 from i to j using intermediate vertices (1..k−1). Each path[i][j] is initialized to
9 edgeCost(i,j).
10 */
11
12 procedure FloydWarshall()
13 for k := 1 to n
14 for i := 1 to n
15 for j := 1 to n
16 path[i][j] = min (path[i][j], path[i][k]+path[k][j]);
हो सकता है कि जिस तरह से एल्गोरिदम एक पाठ्यपुस्तक में लिखे गए हैं यह डिज्कस्ट्रा की एकमात्र एकल स्रोत के लिए प्रयोग किया जाता है की तरह लग रहे हैं, लेकिन इन एल्गोरिदम कर सकते हैं बनाता है लगभग कोई संशोधन के साथ एकाधिक स्रोत और एकाधिक गंतव्य के लिए उपयोग किया जाना चाहिए। डिजस्ट्रा के लिए आप अपने स्रोत वर्टेक्स को दूरी = 0 के साथ प्राथमिकता कतार में दबाकर शुरू करते हैं, यदि आप कई स्रोत चाहते हैं तो बस अपने सभी स्रोतों को दूरी = 0 के साथ दबाएं। वैकल्पिक रूप से आप अपने सभी स्रोत शीर्षकों में शून्य-वज़न किनारों के साथ एक एकल वर्टेक्स जोड़ सकते हैं, फिर उस वर्टेक्स को अपने वास्तविक स्रोत के रूप में उपयोग करें। –
सटीक डुप्लिकेट: http://programmers.stackexchange.com/questions/158613/am-i-right-about-the-differences-between-floyd-warshall-dijkstras-and-bellman –