RS
Size: a a a
RS
AC
RS
AC
ST
RS
RS
AC
ST
AC
RS
ST
ST
RS
D
D
D
(def graph {:a [:b :c]
:b [:d :e]
:c [:b]
:d [:f]})
(defn dfs [g start]
(loop [stack (get g start)
path [start]]
(if (empty? stack)
(distinct path)
(let [curr (peek stack)
stack' (into (pop stack) (remove (set path) (get g curr)))
path' (conj path curr)]
(recur stack' path')))))
(dfs graph :a)
ST
(def graph {:a [:b :c]
:b [:d :e]
:c [:b]
:d [:f]})
(defn dfs [g start]
(loop [stack (get g start)
path [start]]
(if (empty? stack)
(distinct path)
(let [curr (peek stack)
stack' (into (pop stack) (remove (set path) (get g curr)))
path' (conj path curr)]
(recur stack' path')))))
(dfs graph :a)
D
DL
(def graph {:a [:b :c]
:b [:d :e]
:c [:b]
:d [:f]})
(defn dfs [g start]
(loop [stack (get g start)
path [start]]
(if (empty? stack)
(distinct path)
(let [curr (peek stack)
stack' (into (pop stack) (remove (set path) (get g curr)))
path' (conj path curr)]
(recur stack' path')))))
(dfs graph :a)