Upcoming SlideShare
×

# Networks dijkstra's algorithm- pgsr

2,289 views

Published on

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
2,289
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
117
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Networks dijkstra's algorithm- pgsr

1. 1. DIJKSTRAS ALGORITHM,BYDR HJH RAHMAH BT MURSHIDI
2. 2. INTRODUCTION Dijkstras algorithm, named after itsdiscoverer, Dutch computer scientist EdsgerDijkstra A greedy algorithm that solves the single-sourceshortest path problem for a directed graph withnon negative edge weights.
3. 3. INTRODUCTION For example, if the vertices of the graphrepresent cities and edge weights representdriving distances between pairs of citiesconnected by a direct road, Dijkstras algorithmcan be used to find the shortest route betweentwo cities.
4. 4.  The input of the algorithm consists of a weighteddirected graph G and a source vertex s in G Denote V as the set of all vertices in the graph G. Each edge of the graph is an ordered pair ofvertices (u,v) This representings a connection from vertex u tovertex v
5. 5.  The set of all edges is denoted E Weights of edges are given by a weight functionw: E → [0, ∞) Therefore w(u,v) is the cost of moving directlyfrom vertex u to vertex v The cost of an edge can be thought of as (ageneralization of) the distance between thosetwo vertices
6. 6.  The cost of a path between two vertices is thesum of costs of the edges in that path For a given pair of vertices s and t in V, thealgorithm finds the path from s to t with lowestcost (i.e. the shortest path) It can also be used for finding costs of shortestpaths from a single vertex s to all other verticesin the graph.
7. 7. BOXES AT EACH NODEOrder oflabellingLabel (i.ePermanentlabel)Workingvalues
8. 8. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM FROM S TO TSABTDC3115864124Step 1Label start node Swith permanent label(P-label) of 0.1 04
9. 9. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM431 0SABTDC3115864124Step 2For all nodes thatcan be reacheddirectly from S,assign temporarylabels (T-labels)equal to their directdistance from S64
10. 10. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM42 31 0SABTDC3115864124Step 3Select the node withsmallest T label andmakes its labelpermanent. In thiscase the node is A.The P-labelrepresents theshortest distancefrom S to that node.Put the order oflabeling as 2.6
11. 11. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM42 31 0SABTDC3115864124Step 4Consider all nodesthat can be reachedfrom A, that are Band T. Shortestroute from S to B viaA is 3+4 =7, but B isalready labelled as 6and it’s the best sofar. The shortestroute from S to T viaA is 3 + 11 = 14. PutT-label as 14 in T6414
12. 12. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM3 42 31 0SABTDC3115864124Step 5Compare node T, Band C. The smallestT label is now 4 at C.Since this valuecannot be improved,it becomes P-label of4. Put the order oflabeling at C as 36414
13. 13. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM3 42 31 0SABTDC3115864124Step 6Consider all nodes thatcan be reached from C,that are B and D.Shortest route from S to Bvia C is 4+1 =5 which isshorter than 6. Change Tlabel 6 to P label 5. Theshortest route from S to Dvia C is 4 + 4 = 8. Put T-label as 8 in D. CompareB and D. B is less than D,so the next node is B. Putthe order of labeling at Bas 44 54148
14. 14. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM3 442 331 0SABTDC3115864124Step 7Consider all nodes thatcan be reached from B;that are D and T.Shortest route from S toD via B is 5+2 =7 whichis shorter than 8. ChangeT label 8 to P label 7. Theshortest route from S to Tvia B is 5 + 8 = 13. This issmaller than 14 sochange to 13 in T as Tlabel. Compare T and D.D is less than T so choseD as the next node. Putthe order of labeling as 5in D4 56,546 1314,135 78,7
15. 15. TO FIND THE SHORTEST ROUTE BYDIJKSTRA’S ALGORITHM3 442 331 0SABTDC3115864124Step 8The last node is T. Put theorder of labeling as 6 in T.Compare the routes fromS to T via A (3 + 11 =14),via B ( 5 + 8 =13) and viaD (7 + 5 =12). It seemsthat the shortest routefrom S to T is via D.Change the T label in T(13) to P label with thevalue 12. Therefore theshortest way from S to Tis SCBDT which is 124 56,546 1214,13,125 78,7