Dijkstra's algo doubt

if we want to update prv dist then it will be in set na so why to check if its not there?

@guptashubham210a, its not necessary , if the childpair node has’nt been visited before ,i.e dist[childPair.first]=INT_MAX, then it won’t be present in the set , basically what we do is to find a node which is present at minimum distance from the set , and pick that node out and insert all of its neighbour in the set , at this step , we will encounter two situations for each neighbour node,

  1. the neighbour node is already present in the set, might have been neighbour of some other node present ,in that set, so we delete previous value and insert pair with updated distance.
  2. node is not present in the set, so we insert the pair.

I hope you got what i am saying ,
In case of any doubt feel free to ask :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.