Loading section...
Path Problems and Backtracking
Concepts: pyPathSum, pyBacktracking, pyQueryPlanPaths
Path problems on trees follow a specific DFS pattern: carry state down from root to leaf, check the condition at leaves, and backtrack (undo the state change) as you return up the tree. The key discipline is clean backtracking — you must undo exactly what you added before returning. If you forget to undo, the path accumulates stale nodes from previous DFS branches and the output is wrong. All Root-to-Leaf Paths with Target Sum DE Application: Tracing Execution Paths in a Query Plan A database query plan is a tree of operators: Scan, Filter, HashJoin, Sort, Aggregate. Each leaf is a table scan. Finding all root-to-leaf paths in the query plan gives you every execution path — every sequence of operations the database will perform on a source table. This is how query plan analyzers work when