File tree Expand file tree Collapse file tree
L-A/0001 MemoizedNthNumberFibonacci ( L-A )/0002 BFSTraverseGraph Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,11 +29,34 @@ class Node {
2929 return false ;
3030 }
3131 ```
32+
33+ ## How it works
34+
35+ - We create a queue and add the start node to it.
36+ - We create a visited set to keep track of the nodes we have visited.
37+ - We loop through the queue while it is not empty.
38+ - We shift the first node off the queue and check if it is the target node.
39+ - If it is, we return true.
40+ - If it is not, we check if we have visited the node already.
41+ - If we have, we continue.
42+ - If we have not, we add the node to the visited set.
43+ - We then push all of the neighbors of the node to the queue.
44+ - We then loop again.
45+ - We repeat this process until the queue is empty.
46+ - If we have not found the target node, we return false.
47+
3248
3349## References
3450
3551- [ GeeksforGeeks] ( https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/ )
3652- [ StackOverflow] ( https://stackoverflow.com/questions/2505431/breadth-first-search-and-depth-first-search )
3753
54+
3855## Problem Added By
3956- [ GitHub] ( https://github.com/Akbar-Ahmed )
57+
58+
59+ ## Contributing
60+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
61+
62+ Please make sure to update tests as appropriate.
You can’t perform that action at this time.
0 commit comments