dijkstra s algorithm
play

Dijkstras Algorithm Problem Solving Club February 1, 2017 - PowerPoint PPT Presentation

Dijkstras Algorithm Problem Solving Club February 1, 2017 Dijkstras algorithm Dijkstras is a greedy algorithm that finds shortest paths from a single source to every other vertex in the graph. As usually implemented: Works


  1. Dijkstra’s Algorithm Problem Solving Club February 1, 2017

  2. Dijkstra’s algorithm ◮ Dijkstra’s is a greedy algorithm that finds shortest paths from a single source to every other vertex in the graph. ◮ As usually implemented: ◮ Works for weighted graphs with non-negative weights . ◮ Works for directed and undirected graphs. ◮ Runs in O (( V + E ) log V ). 1 0 1 8 4 2 4 1 3 2 3

  3. Binary heap (priority queue) data structure ◮ A binary heap is a data structure with two operations: ◮ Insert: Insert an element into the heap. ◮ Extract: Remove the max (or min) element from the heap. ◮ Both operations take at worst O (log N ). ◮ C++ std::priority queue, Java PriorityQueue

  4. Dijkstra’s Algorithm Procedure: 1. Assign all nodes a (tentative) distance of infinity. 2. Mark all nodes as unvisited. 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. If [distance to current node + edge weight] is smaller than the current tentative distance of that node, update its tentative distance. 5. Mark the current node as visited. 6. Set the current node to the unvisited node with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  5. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 ∞ infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node ∞ ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  6. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node ∞ ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  7. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 4 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  8. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 4 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  9. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 4 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  10. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance ∞ of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  11. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  12. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  13. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 ∞ with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  14. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 6 with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  15. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 6 with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  16. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 9 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 6 with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

  17. Dijkstra’s Algorithm: An Example Procedure: 1 1. Assign all nodes a (tentative) distance of 0 1 infinity. 2. Mark all nodes as unvisited. 8 3. Set the current node as start point and set its distance to zero. 4. For the current node, consider all neighbours. 4 If [distance to current node + edge weight] 2 is smaller than the current tentative distance 7 of that node, update its tentative distance. 1 5. Mark the current node as visited. 3 6. Set the current node to the unvisited node 3 6 with the smallest tentative distance, and go back to step 4 until there are no more unvisited nodes.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend