in the code : when i will be equal to 35 j will have value 36 and we will pass (35,36) to the addEdge function so if we are telling it that there is an edge between 35 nd 36 it means there is a node with value 36 present in it so why are we inserting it again in the last statemen.
Why 36,36 is inserted in the end?
this is because
there is no node in graph with 36
why??
because
for i=36
as j=i+dice+board[i];
so min value of j is 37(36+1) but according to our condition j<=36 edge from 36 can’t be added means graph doesn’t know there is a node with 36
although there are node from which you can reach 36 for example
31,32,33,…
but 36 is not present in adjancylist it is present in list of 31,32,.
hence when you update distance of all node as INT_MAX then 36 will not update as it is not present in adjlist
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course
i understood what you said but what i am asking is that when i=35
then j=i+dice i.e. j=35+1=36 and then we make a call to addEdge(i,j) i.e. addEdge(35,36)
and after making this call an edge between 35 and 36 will get inserted then there should be no need of doing that last step of calling addEdge(36,36) ?
that is what i explained here