Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Dijkstar's Algo to find shortest path from 1 to N

$
0
0

In The Dijkstra's algo we need to extract the minimum of D where D is the distance from node 0. But as D gets updated with the distance randomly how could we extract the minimum. Eg: Let at an instance we have the below array and we have used the node 0(its distance to itself is always 0) and accordingly its adjacent node2 and node5 get updated with distance from node 0. D: 0 INF 3 INF INF 1 INF

If we use O(n) then ultimately we are using O(n^2) as we will be updating the adjacent of node 5 and again extracting the minimum by using O(n). Is there a better approach to extract the minimum??


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>