codezoned / ScriptsDump

The biggest dump of scripts ever!
http://www.codezoned.com/
143 stars 173 forks source link

Dijkstra's single source shortest path #279

Closed prasantraj0808 closed 1 year ago

prasantraj0808 commented 1 year ago

Like Prim’s MST, generate a SPT (shortest path tree) with a given source as a root. Maintain two sets, one set contains vertices included in the shortest-path tree, other set includes vertices not yet included in the shortest-path tree. At every step of the algorithm, find a vertex that is in the other set (set not yet included) and has a minimum distance from the source.