1 / 6

Dijkstra’s Algorithm

Dijkstra’s Algorithm. Demo. Dijkstra’s Algorithm: Implementation. Dijkstra ( G , s ) Initialize the attributes (Distance( s ) = 0,  for all others) put all vertices into a queue While the queue is not empty Dequeue , let v be the element dequeued with minimal distance,

Download Presentation

Dijkstra’s Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dijkstra’s Algorithm

  2. Demo

  3. Dijkstra’s Algorithm: Implementation Dijkstra(G, s) Initialize the attributes (Distance(s) = 0,  for all others) put all vertices into a queue While the queue is not empty Dequeue, let v be the element dequeued with minimal distance, For each neighbor u of v that is still in the queue If Distance(u) > Distance(v) + weight((v,u)) Distance(u) = Distance(v) + weight((v,u)) Parent(u)=v

  4. Complexity • O(|V|2) • Can it be done better • Use min-heap to improve efficiency

  5. Dijkstra’s Algorithm: Implementation Dijkstra(G, s) Initialize the attributes (Distance(s) = 0,  for all others) Enqueue all vertices into min-distance priority queue While the queue is not empty Dequeue, let v be the element dequeued For each neighbor u of v that is still in the queue If Distance(u) > Distance(v) + weight((v,u)) Distance(u) = Distance(v) + weight((v,u)) Parent(u)=v

  6. Complexity changed to • O(|V|+|E|)log|V| • Why?

More Related