Upcoming SlideShare
×

Dijkstra

6,618 views

Published on

Published in: Technology
5 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total views
6,618
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
325
0
Likes
5
Embeds 0
No embeds

No notes for slide

Dijkstra

1. 1. Presentation on prolog : Dijkstra’s Algorithm
2. 2. A graph is defined as a set of nodes and a set of edges, where each edge is a pair of nodes.
3. 3. There are several ways to represent graphs in Prolog.  One method is to represent each edge separately as one clause (fact). • edge(1, 5). edge(1, 7). edge(2, 1). edge(2, 7). edge(3, 1). edge(3, 6). edge(4, 3). edge(4, 5). edge(5, 8). edge(6, 4). edge(6, 5). edge(7, 5). edge(8, 6). edge(8, 7). We call this edge-clause form W
4. 4.  Another method is to represent the whole graph as one data object. According to the definition of the graph as a pair of two sets (nodes and edges).  EXAMPLE :  graph([b,c,d,f,g,h,k],[e(b,c),e(b,f),e(c,f),e(f,k),e(g,h)]) .  We call this graph-term form. Note, that the lists are kept sorted, they are really sets, without duplicated elements. Each edge appears only once in the edge list.  The graph-term form is a default representation
5. 5.  A third representation method is to associate with each node the set of nodes that are adjacent to that node .  EXAMPLE: [n(b,[c,f]), n(c,[b,f]), n(d,[]), n(f,[b,c,k]), .........]. 
6. 6. Directed graphs  These are represented by ordered pairs  To represent a directed graph, the forms discussed above are slightly modified. The example graph is represented as follows:  When the edges are directed we call them arcs Arc-clause form  arc(s,u). arc(u,r). Graph-term form  digraph([r,s,t,u,v],[a(s,r),a(s,u),a(u,r),a(u,s),a(v,u)]) Adjacency-list form  [n(r,[]),n(s,[r,u]),n(t,[]),n(u,[r]),n(v,[u])]
7. 7. Dijkstra  Dijkstra's algorithm, introduced by the dutch computer scientist , is a graph searching algorithm.  Dijkstra’s algorithm is used to solve the problems of finding the shortest path between edge - weighted graphs in which all the weights are non-negative.
8. 8. Basic features of Dijkstra's algorithm  For a given source vertices it finds the lowest cost(i.e. The shortest path) for every other vertices .  It can also be used to find the lowest cost for a particular destination by the stopping the algorithm in between.  For example:- If the vertices represents the cities and the edge path cost represents the distance between pair cities then dijkstra’s can be used to find the shortest route between one city and all other.
9. 9. An example of Dijkstra’s Algorithm
10. 10. Dijkstra’s Algorithm can be applied to network routing, as it can be used to find the shortest path from any source computer to any other computer in the network .
11. 11. Basic steps towards the algorithm  The algorithm begins by initializing any vertex in the graph (vertex A, for example) a permanent label with the value of 0, and all other vertices a temporary label with the value of 0.
12. 12. Basic steps towards  The algorithm then proceeds to select the least cost edge connecting a vertex with a permanent label (currently vertex A) to a vertex with a temporary label (vertex B, for example). Vertex B's label is then updated from a temporary to a permanent label. Vertex B's value is then determined by the addition of the cost of the edge with vertex A's value
13. 13. Basic steps towards  The next step is to find the next least cost edge extending to a vertex with a temporary label from either vertex A or vertex B (vertex C, for example), change vertex C's label to permanent, and determine its distance to vertex A.
14. 14. Basic steps towards This process is repeated until the labels of all vertices in the graph are permanent.
15. 15. Start Identify source node and destination node as V1 and V2 Set V1 as T-node Set T-node’s label to “permanent” and update neighbor's status record set Identify the tentative node linked to V1 that has the lowest weight and set it as T-node Is T-Node is V2? END Based on information in status record set, do these until u reach V1. The string of link represents the best route