From 8c87c2433cacaeda1a1f54e4eec28597928785db Mon Sep 17 00:00:00 2001 From: muskansharma2000 <61937946+muskansharma2000@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:34:17 +0530 Subject: [PATCH] Update README.md --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 0732d0b..b179b25 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,29 @@ Language : C Ps:Share some of your algoritms ^_^ +Shortest path by Dijkstra added to dynamic programming +sudo code: + function Dijkstra(Graph, source): + dist[source] := 0 // Distance from source to source + for each vertex v in Graph: // Initializations + if v ≠ source + dist[v] := infinity // Unknown distance function from source to v + previous[v] := undefined // Previous node in optimal path from source + end if + add v to Q // All nodes initially in Q + end for + + while Q is not empty: // The main loop + u := vertex in Q with min dist[u] // Source node in first case + remove u from Q + + for each neighbor v of u: // where v has not yet been removed from Q. + alt := dist[u] + length(u, v) + if alt < dist[v]: // A shorter path to v has been found + dist[v] := alt + previous[v] := u + end if + end for + end while + return dist[], previous[] + end function