diff --git a/graph-search/notes.md b/graph-search/notes.md index e0d0f6a6e7785c422b8e76bd71e31f6fd8fec22f..b84f4028202bd0a53b16af34d395afbddee8a33c 100644 --- a/graph-search/notes.md +++ b/graph-search/notes.md @@ -133,8 +133,35 @@ How many moves does it take to reverse the string `123`? ## Recursive Depth-First Search (DFS) -* Worklist: … +* Worklist: Call Stack Activation Frames Backpointers Returned ----------------------------------- ------------ ------------------ - edge = (⊥, a), incidence = … + edge = (⊥, a), incidence = (a, c) a → (⊥, a) [a, c, b, e, f, d] + edge = (a, c), incidence = (c, b) c → (a, c) [c, b, e, f, d] + edge = (c, b), incidence = (b, e) b → (c, b) [b, e, f, d] + edge = (b, a) ⊥ + edge = (b, e), incidence = (e, f) e → (b, e) [e, f, d] + edge = (e, f), incidence = (f, d) f → (e, f) [f, d] + edge = (f, d) d → (f, d) [d] + ↑ ↑↑↑↑↑↑ + Don't need this Don't need this + +For comparison, the iterative work has the same edges checked off as workitems, the same backpointers dictionary, and the same path: + + Worklist Backpointers + -------- ------------ + (⊥, a) ✓ a → (⊥, a) + (a, c) ✓ c → (a, c) + (c, e) b → (c, b) + (c, b) ✓ e → (b, e) + (b, e) ✓ f → (e, f) + (b, a) ✓ d → (f, d) + (e, d) + (e, f) ✓ + (f, c) + (f, d) ✓ + + Reversed Path + ---- + d ← f ← e ← b ← c ← a