dijkstra's algorithm ppg

Upload: eida-wahida-zl

Post on 03-Apr-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Dijkstra's Algorithm Ppg

    1/12

    by

    MDM KHARSHIAH KHALID

  • 7/29/2019 Dijkstra's Algorithm Ppg

    2/12

    Edsger Wybe Dijkstra (pronounced

    Deekstrah) (1930-2002)

    b. Rotterdam, Netherlands; worked

    in Amsterdam and also Texas,USA

    Edsger Dijkstra studied TheoreticalPhysics at the University of Leidenbeforemoving into the field of ComputerScience. He worked for the

    MathematischCentrum in Amsterdam and then theBurroughs Corporation, which hadprogressedfrom making adding machines to

    typewriters and computers. He laterheld theSchlumberger Centennial Chair inComputer Sciences at the Universityof Texas.

  • 7/29/2019 Dijkstra's Algorithm Ppg

    3/12

    Edsger Wybe Dijkstra (pronounced

    Deekstrah) (1930-2002)

    b. Rotterdam, Netherlands; worked

    in Amsterdam and also Texas, USA

    In Graph Theory, he is known best for

    Dijkstras Algorithm for finding theShortest Path between two points in anetwork, which he developed in 1959.This is alabelling procedure which identifies thesmallest total path length to each vertex

    fromthe starting point. Tracing back from thefinish vertex finds the shortest path itself.It is an example of a greedy algorithmbecause of the step during each iterationwherethe vertex with the lowest working valueis chosen as the best and is thenpermanentlylabelled.

  • 7/29/2019 Dijkstra's Algorithm Ppg

    4/12

    Order of

    labelling

    Label (i.e

    Permanentlabel)

    Working

    values

  • 7/29/2019 Dijkstra's Algorithm Ppg

    5/12

    1 0

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 1

    Label start node S

    with permanent label

    (P-label) of 0.4

  • 7/29/2019 Dijkstra's Algorithm Ppg

    6/12

    4

    3

    1 0

    6

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 2

    For all nodes that

    can be reached

    directly from S,

    assign temporary

    labels (T-labels)

    equal to their direct

    distance from S

    4

  • 7/29/2019 Dijkstra's Algorithm Ppg

    7/12

    4

    2 3

    1 0

    6

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 3

    Select the node with

    smallest T label and

    makes its label

    permanent. In this

    case the node is A.

    The P-label

    represents the

    shortest distancefrom S to that node.

    Put the order of

    labeling as 2.

  • 7/29/2019 Dijkstra's Algorithm Ppg

    8/12

    4

    2 3

    1 0

    6

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 4

    Consider all nodes

    that can be reached

    from A, that are B

    and T. Shortestroute from S to B via

    A is 3+4 =7, but B is

    already labelled as 6

    and its the best sofar. The shortest

    route from S to T via

    A is 3 + 11 = 14. Put

    T-label as 14 in T

    4

    14

  • 7/29/2019 Dijkstra's Algorithm Ppg

    9/12

    3 4

    2 3

    1 0

    6

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 5

    Compare node T,

    B and C. The

    smallest T label is

    now 4 at C. Sincethis value cannot

    be improved, it

    becomes P-label

    of 4. Put the orderof labeling at C as

    3

    4

    14

  • 7/29/2019 Dijkstra's Algorithm Ppg

    10/12

    3 4

    2 3

    1 0

    4 5

    S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 6

    Consider all nodes that

    can be reached from C,

    that are B and D.

    Shortest route from S to B

    via C is 4+1 =5 which is

    shorter than 6. Change Tlabel 6 to P label 5. The

    shortest route from S to D

    via C is 4 + 4 = 8. Put T-

    label as 8 in D. Compare

    B and D. B is less than D,so the next node is B. Put

    the order of labeling at B

    as 4

    4

    14

    8

  • 7/29/2019 Dijkstra's Algorithm Ppg

    11/12

    3 4

    4

    2 3

    3

    1 0

    4 5

    6,5S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 7

    Consider all nodes thatcan be reached from B;

    that are D and T.

    Shortest route from S to

    D via B is 5+2 =7 which

    is shorter than 8. ChangeT label 8 to P label 7. The

    shortest route from S to T

    via B is 5 + 8 = 13. This is

    smaller than 14 so

    change to 13 in T as Tlabel. Compare T and D.

    D is less than T so chose

    D as the next node. Put

    the order of labeling as 5

    in D

    4

    6 13

    14,13

    5 7

    8,7

  • 7/29/2019 Dijkstra's Algorithm Ppg

    12/12

    3 4

    4

    2 3

    3

    1 0

    4 5

    6,5S

    A

    B

    T

    D

    C

    3

    11

    58

    6

    41

    2

    4

    Step 8

    The last node is T. Put theorder of labeling as 6 in T.

    Compare the routes from

    S to T via A (3 + 11 =14),

    via B ( 5 + 8 =13) and via

    D (7 + 5 =12). It seemsthat the shortest route

    from S to T is via D.

    Change the T label in T

    (13) to P label with the

    value 12. Therefore theshortest way from S to T

    is SCBDT which is 12

    4

    6 12

    14,13,12

    5 7

    8,7