3 ms·
You're given a starting node in a linked data structure and you want to visit, collect, or search all of the nodes that it can reach, and do so without duplicat
by pklausler 11y ago
You're given a starting node in a linked data structure and you want to visit, collect, or search all of the nodes that it can reach, and do so without duplication. If you can solve that problem correctly, you've just used or re-invented one of DFS or BFS, and could come up with the other one after a moment of thought about the order in which you visit the nodes. These are not magic spells that you have to go to Hogwarts to memorize; they're the two obvious approaches to solving a really straight-forward problem statement.