i did not understand the logic behind g.addEdge(36,36)
Snakes n laaders(Grpah)
Hello @dare_devil_007,
I cannot find this g.addEdge(36,36) statement anywhere in the code.
addEdge is used to mark the paths from a particular node, this way we are creating a graph.
Suppose, you are at the node with value 1 i.e. the starting position.
Now, the for loop in the following code is finding all the possible positions(i.e. nodes) we can reach for a particular through of the dice.
And we are creating an edge for that path.
Then, we are just doing BFS to find the required path.
Hope, this would help.
yeah i understood the working of it but there is a line add.Edge(36,36) in the code,it was mentioned that it is to tel the graph that 36 vertex is in it.I did not understand that one line
Hey @dare_devil_007,
There might be a mistake in the explanation. Because there are 100 vertices in total as there are 100 possible positions to land.
You can refer to the above code that i have shared.
It does not contain any such statement.