← Visualizers
Graphs · Enumerating paths · anti-pattern LeetCode 797

All Paths From Source to Target / visualized

The input is a DAG, so a visited set is not merely unnecessary here — it is wrong. It silently drops every path that would have gone through a node some earlier path already used. Flip the toggle and watch the answers disappear one at a time.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

current node on the path target blocked by visited
O(2ⁿ·n) time — that is the size of the output, not waste  ·  a DAG cannot revisit a node within one path, so nothing needs marking; the undo that backtracking usually needs is just path.removeLast().