I've been doing a tutorial in OCaml. The tutorial taught me how to do a breadth-first search on a graph, which I can implement fine. However, I've been struggling with an algorithm for a depth-first search, which is one of those things where the tutorial goes, "We suggest you try this on a depth-first method, but we won't tell you how to do it."
I'm trying to implement it like so: let rec dfs graph start end
. Which is to say, I've been trying to do it where I take in a list of edges (graph
), a starting node (start
), and an ending node (end
).
I've created my graph using a list of edges...
let edges = [
("a", "b"); ("a", "c");
("a", "d"); ("b", "e");
("c", "f"); ("d", "e");
("e", "f"); ("e", "g")
];;
However, I'm totally lost about where to go from here.