Go as deep as possible before backtracking. DFS is the workhorse of tree and graph problems — learn it on trees first, then add one line for graphs.
What Is It?
Depth-first search explores one branch all the way to the bottom before coming back up and trying the next branch. You visit a node, then recurse (or push onto a stack) its children/neighbors, going deeper each time.
On a binary tree, this is clean and natural: check if the node is null (base case), do something with the node, recurse left and right, combine results. The call stack handles backtracking for you.
On a graph, the same idea applies, but with one critical addition: graphs can have cycles, so you must track visited nodes with a seen array. Without it, you'll loop forever. That's the only fundamental difference — tree DFS is just graph DFS where you don't need a visited check.