diff --git a/notes-and-examples/2026.07.21/depth-first-search.md b/notes-and-examples/2026.07.21/depth-first-search.md new file mode 100644 index 0000000..1682db0 --- /dev/null +++ b/notes-and-examples/2026.07.21/depth-first-search.md @@ -0,0 +1,52 @@ +## Traversal introduction + +Many algorithms that involve graphs must involve some way to traverse the elements of a graph. The two simplest ways of traversal are depth-first search (DFS) and [breadth-first search (BFS)](https://en.wikipedia.org/wiki/Breadth-first_search). The major difference here is the *order* in which nodes are traversed. + +If we start from vertex 0 in the tree, in what order would you expect depth-first search to traverse the nodes? (There are multiple correct answers!) + +``` + 0 + / \ + 1 2 + / \ + 3 4 +``` + +Note that a single traversal step checks for already-visited nodes. So, if the path is `0 -> 1 -> 3`, the path cannot become `0 -> 1 -> 3 -> 1`. + +What about starting from vertex 0 in this graph? + +``` + 0 --- 1 + | | + 3 --- 2 +``` + +What about this one? + +``` + 0 + / \ + 1 5 + / \ \ + 2 3 6 + \ / / + 4 7 + \ / + 8 +``` + +## Formalizing the algorithm + +Based on these examples, can we create a formal algorithm that takes a starting node, producing a valid traversal path for all three graphs? + +An example for this graph: + +``` + 0 --- 1 + | | + 3 --- 2 +``` + +- Arguments: starting node `0` +- Expected output: diff --git a/notes-and-examples/2026.07.21/overview.md b/notes-and-examples/2026.07.21/overview.md new file mode 100644 index 0000000..3f3de60 --- /dev/null +++ b/notes-and-examples/2026.07.21/overview.md @@ -0,0 +1,3 @@ +## Outline + +To make our knowledge of graphs useful, we'll go over our first traversal method today: [depth-first search](./depth-first-search.md). If we have time we'll go over breadth-first search, which is the relative to depth-first search.