Hi,

I am new to BFS and I have just started to solve BFS questions and I am stuck at understanding which approach to follow for the solutions. Let me cite the examples of Number of Islands problem( using BFS) and Wall and Gates problem( Problem no 286). In problems like Number of Islands/Rotten oranges I see that they start BFS as soon as they find the root node and then start adding rest of the nodes to the Queue (The order of insertion in the queue affects the result), while in problems like Wall and Gate all the root nodes are found and then BFS is started. Why is that and how would we know which approach to follow?

Any other pointers/suggestion would be a great help as well.

Thanks a lot in advance.

Regards

Comments (0)