AlgoViz
HomeDepth-First Search

Depth-First Search

Dive deep first — trees, recursion, and connectivity.

0/ 25 understood · 0%
Walkthroughs
17
Problems
25
Start here
25 shown
  1. Maximum Depth of Binary Tree1 + max(left depth, right depth)Easy
  2. Number of IslandsSink each connected blob of landMedium
  3. Clone GraphDFS with a visited→copy mapMedium
  4. Practice problems
  5. IntroductionGo deep first, back up when stuckMedium
  6. FundamentalsBase case, process, recurseMedium
  7. Return ValuesLet each call hand a fact upwardMedium
  8. Path SumSubtract as you descend, check at the leafMedium
  9. Passing Values Down and UpContext descends, results ascendMedium
  10. Validate Binary Search TreeCarry a valid range downwardMedium
  11. Binary Tree TiltReturn the subtree sum, accumulate the tiltMedium
  12. Diameter of a Binary TreeReturn the height, track the best bendMedium
  13. Path Sum IIThe same descent, recording every pathMedium
  14. Longest Univalue PathExtend only through equal valuesMedium
  15. Invert Binary TreeSwap the children, everywhereMedium
  16. Same TreeBoth null, or both equal with matching subtreesMedium
  17. Lowest Common Ancestor of a Binary TreeThe first node with a hit on both sidesMedium
  18. Binary Tree Maximum Path SumBend at most once, drop negative branchesMedium
  19. Serialize and Deserialize Binary TreePreorder with null markersMedium
  20. Graphs OverviewNodes and edges, and the four variationsMedium
  21. Adjacency ListEach node keeps a list of its neighboursMedium
  22. Copy GraphMap original nodes to their clonesMedium
  23. Graph Valid TreeConnected, and exactly V-1 edgesMedium
  24. MatricesA grid is a graph with implicit edgesMedium
  25. Flood FillRecolour the connected regionMedium
  26. Pacific Atlantic Water FlowSearch inland from both oceansMedium