Attribution Non-Commercial (BY-NC)

8 views

Attribution Non-Commercial (BY-NC)

- Modi Method
- A2 1.3 Packet
- MC0063 Discrete Mathematics Model Question Paper
- aldrin
- volume 02
- Elenberg3profileKDD15
- Route Planning
- 10.1.1.100
- Understanding Voronoi scipy
- Assignment Data Mining
- solusisimulasi2
- lec9
- CV and Grades Sheet - Nadav Schweiger
- Metadata Challenge for Query Processing Over Heterogeneous Wireless Sensor Network
- dynamicProgramminggeneral
- HW2
- AI_DanielAdinugroho(4)1_4
- Saharon Shelah- Zero One Laws for Graphs with Edge Probabilities Decaying with Distance. Part 1
- Yoshiharu Kohayakawa et al- Multidimensional Cube Packing
- Lib Guide

You are on page 1of 11

Bellman-Ford Algorithm

Section authors: Noboru Obata, Lei Zhang, and Huai Kai Lin.

Strategy Specialized 1.4

Edge Comparison Based 3.2

Iterative 1.8

Bellman-Ford Algorithm

Renement of: Single Source Shortest Path (3.7), Iterative Algorithm (1.8).

Prototype:

template <class Graph, class Size, class P, class T, class R> bool bellman_ford_shortest_paths (Graph& g, Size N, const bgl_named_params<P, T, R>& params)

Input: A graph g, either directed and undirected, with N vertices, and a named parameter params which may contain the following property maps. An edge weight map w map. A vertex distance map d map. This must be initialized such that d map[u] = for all vertices u in the graph, except for the source vertex s, d map[s] = 0, by which the source vertex is identied. A predecessor map p map (optional). This must be initialized to have p map[u] = u for all vertices u in the graph. Output: True if the graph contains no negative-weight cycles that are reachable from the source; False otherwise.

Eects: For every vertex u in the graph, d map[u] is the shortest path weight from the source vertex s. (If a vertex u is not reachable from the source vertex, d map[u] = .) If a vertex u is reachable from the source vertex s, then p map[u] = v and u = v, where v is the parent node of u in the minimum spanning tree rooted at s. If either u = s or a vertex u is not reachable from s, then p map[u] = u. Pseudocode: The implementation in BGL has an important change from the algorithm presented in CLRS. A ag relaxed is turned True only if an edge is relaxed in the loop of lines 712. If no edges are relaxed, then the outer loop of lines 516 is terminated immediately. This improvement dramatically decreases the number of outer loop iterations actually executed.

Bellman-Ford-BGL(G, w, s) 1: for each vertex v V [G] do 2: d[v] 3: end for 4: d[s] 0 5: for i 1 to |V [G]| do 6: relaxed False 7: for each edge (u, v) E[G] do 8: if d[v] > d[u] + w(u, v) then Relaxation call 9: d[v] d[u] + w(u, v) Relaxation step 10: relaxed True 11: end if 12: end for 13: if relaxed = False then 14: exit the loop 15: end if 16: end for 17: for each edge (u, v) E[G] do 18: if d[v] > d[u] + w(u, v) then 19: return False 20: end if 21: end for 22: return True

Asymptotic complexity: Average case (random data): O(|V ||E|) Worst case: O(|V ||E|) Complexity in terms of operation counts: The complexity of the Bellman-Ford algorithm depends on the number of edge examinations, or relaxation calls (line 8). (Note this is dierent from relaxation steps which refer to the actual changes performed in line 9.) As mentioned, the number of relaxation calls can be smaller than |V ||E| with the BGL implementation. In fact, it is much smaller than |V ||E| in the average case. The rst table shows the number of relaxation calls for random directed graphs with non-negative random edge weights, allowing self-edges and parallel edges. Vertices, edges, and operation counts are shown in thousands. For example, the top-left cell indicates that operation counts are 20 with V = 10 and E = 10.

Relaxation calls: Vertices Edges 0.01 0.1 1 10 100 0.01 0.02 0.01 0.01 0.01 0.01 0.1 0.4 0.3 0.1 0.1 0.1 1 3.3 6.3 3.6 1.1 1.0 10 33.7 64.7 91.0 31.0 10.7 100 225.7 794.3 900.0 1238.6 371.4 Directed graph, edge weights [0 : 1000], average of seven attempts. It is hard to create large random graphs with negative edge weights because the they tend to have negative-weight cycles. The second table shows the results with random graphs with some negative weight edges. Vertices Edges 0.01 0.1 1 10 100 0.01 0.03 0.01 0.01 0.01 0.01 0.1 0.3 0.2 0.1 0.1 0.1 1 4.1 6.0 2.4 1.0 1.0 10 92.9 28.5 11.4 100 1357.1 357.1 Directed graph, edge weights [10 : 1000], average of successful seven attempts. Formulas for average case:

Relaxation calls:

Let L be the number of the outer loop (lines 516) executed. Then, the number of relaxation calls is represented exactly by L|E|. So the analysis is done in terms of L, which shows interesting variations as shown in the following contour graph. In the region |E| < |V |, L is very close to 1 because the average size of each connected component is less than 1 and so few edges are relaxed. In the region |E| > |V |, however, L grows in proportion to lg |V |.

100000

10000

|E|

1000

100 14.0 12.0 10.0 8.0 6.0 4.0 2.0 10 10 100 1000 |V| 10000 100000

Worst case operation counts: If the graph contains a negative-weight cycle that is reachable from the source vertex, the algorithm shows the worst case behavior. Again, vertices, edges, and operation counts are shown in thousands. Relaxation calls: Vertices Edges 0.01 0.1 1 10 0.01 0.1 1.0 10.0 100.0 0.1 1.0 10.0 100.0 1000.0 1 10.0 100.0 1000.0 10000.0 10 100.0 1000.0 10000.0 100000.0 Directed graph, edge weights [1000 : 10], maximum of seven attempts. Formulas for worst case: Relaxation calls: 1.00|V ||E|

The plot shows the memory access pattern of the Bellman-Ford algorithm processing a directed graph with 1000 vertices and 4000 edges in the adjacency list representation (vecS, vecS). Only memory accesses to the graph data structure are drawn, and the addresses are shown relative to the smallest one. Red dots are distributed irregularly because edge vectors are allocated dynamically. The Bellman-Ford algorithm makes references to all edges at every

loop of lines 712, which is repeated 9 times in this graph. Since the last loop (lines 1721) makes a similar memory access, 10 repetitions of the same access patterns may be found if the plot is examined carefully. In the worst case, the same access patterns are repeated |V | times.

- Modi MethodUploaded bysimargrewal11
- A2 1.3 PacketUploaded byThomas Carder
- MC0063 Discrete Mathematics Model Question PaperUploaded byashish544170
- aldrinUploaded bysreehari udatha
- volume 02Uploaded byAryafilanEl-jauhar
- Elenberg3profileKDD15Uploaded byAnonymous TiUWU8RMa
- Route PlanningUploaded by4gen_3
- 10.1.1.100Uploaded byVikas Panwar
- Understanding Voronoi scipyUploaded bybalcanera
- Assignment Data MiningUploaded byNada Zhafiera
- solusisimulasi2Uploaded bySyaifullah Mangantjo
- lec9Uploaded bydebdotnet
- CV and Grades Sheet - Nadav SchweigerUploaded byNadav Schweiger
- Metadata Challenge for Query Processing Over Heterogeneous Wireless Sensor NetworkUploaded byJohn Berg
- dynamicProgramminggeneralUploaded byAnu G Nair
- HW2Uploaded bydudewa
- AI_DanielAdinugroho(4)1_4Uploaded byLarry Kenedy
- Saharon Shelah- Zero One Laws for Graphs with Edge Probabilities Decaying with Distance. Part 1Uploaded byJtyhmf
- Yoshiharu Kohayakawa et al- Multidimensional Cube PackingUploaded byMnaom
- Lib GuideUploaded bysocramoluap
- InterceptUploaded bytedwong314
- rounding chandoo.docxUploaded byGmd Nizam
- BioCal Review PacketUploaded byRashad
- MIT18_335JF10_pset2.pdfUploaded byEren Võ
- LOCAS - a low coverage assemly too for resequencing projects - klein.pdfUploaded byspanishvcu
- MathsUploaded byarun kumar
- dxf codepageUploaded byeswarmbbe
- Regular Intuitionistic Fuzzy GraphsUploaded byIoan Degau
- Some Lower and Upper Bounds on the Third ABC Co-indexUploaded byIoan Degau
- MA6566 DM IAT IIUploaded byInfi Coaching Center

- avl2Uploaded bySakshi Bachhety
- Assignment Channel CodingUploaded byLakshitha Prabath Wijesinghe
- compiler design – 2 marks question set with answers _ tutor4cs.pdfUploaded byVinodkumar Done
- Lec 10,11 StacksUploaded byRaja Mustafa
- WorkUploaded byPedro
- BGIUploaded byMaxy911
- Coding Theory,Uploaded byfiraszeki
- fs_enUploaded byJackson Silva
- Big O MIT.pdfUploaded byJoan
- Travelling Salesman ExplainedUploaded byBalaji MT
- NamedGraphs.pdfUploaded byneoferney
- C++_sylUploaded byanon-57741
- CFG DerivationUploaded byGauri Tyagi
- 1-s2.0-S0004370209001398-main.pdfUploaded byClement Thans
- DIGITAL ELECTROddNICS GATE QUESTIONS.pdfUploaded bysachin1391
- CODIGO TUNSTALLUploaded byLidia López
- CSE-IInd_yr_lab_prog(1)Uploaded bykarthickamsec
- Effective Multi-Stage Clustering for Inter- and Intra-Cluster HomogeneityUploaded byijcsis
- Translation in Predicate Logic (Lemmon)Uploaded byVipula Rawte
- Discrete Math- TreeUploaded byLaksana Dewa
- Merge SortUploaded bytushar006
- WYAHUploaded bySoham Chowdhury
- System Data StructureUploaded byAbdullah Holif
- c Program for Unit 3Uploaded byEr Sarbesh
- 25-bnf.pptUploaded byFaatiha
- Eigenfaces vs Fisher Faces PresentationUploaded byMarian Moise
- TSPUploaded byfoxtrot1992
- Number Systems 3Uploaded bykashif780
- Proportional Logic and first order LogicUploaded byRaghavendra Sukumaran
- The Equivalent Conversion Between Regular Grammar and Finite AutomataUploaded byCarlos EQ