You are on page 1of 1

Dijkstra's algorithm //if weight of all egdes == 1 then just use BFS

-edge weights are positive


-prim's algorithm as a base
### Initiliization Stage ###
d[v] = infinity for all
p[v] = -1
finished[v] = 0
d[s] = 0
build Heap H
while(!H.empty())
{
u = H.deleteMH()
finished[u] = 1
neighbors = G[u]
for(int i; i < neighbors.size(); i++)
{
if(d[u] + weight(u,neighbors[i]) < d[neighbors[i])
{
d[neighbors[i]] = d[u] + weight(u. neighors[i])
p[neighbor[i]] = u
}
rebuildheapH
}
return p or d //return shortest path or length of shortest path

You might also like