From 95544077bc587709c2cdde3a320db48f8937f05f Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 21 Jul 2026 16:05:00 -0400 Subject: [PATCH] Add notes for BFS as well --- .../2026.07.21/breadth-first-search.md | 13 +++++++++++++ notes-and-examples/2026.07.21/depth-first-search.md | 12 +++--------- notes-and-examples/2026.07.21/overview.md | 4 +++- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 notes-and-examples/2026.07.21/breadth-first-search.md diff --git a/notes-and-examples/2026.07.21/breadth-first-search.md b/notes-and-examples/2026.07.21/breadth-first-search.md new file mode 100644 index 0000000..fb15a04 --- /dev/null +++ b/notes-and-examples/2026.07.21/breadth-first-search.md @@ -0,0 +1,13 @@ +## Breadth-first search (BFS) + +In the notes on [depth-first search](./depth-first-search.md), we mention that the difference between DFS and BFS is the order in which nodes are traversed. + +Using the same example, what would a breadth-first traversal look like if we start at vertex 0 in this graph? + +``` + 0 --- 1 + | | + 3 --- 2 +``` + +Can we also formalize an algorithm for breadth-first search? diff --git a/notes-and-examples/2026.07.21/depth-first-search.md b/notes-and-examples/2026.07.21/depth-first-search.md index 1682db0..f4e705b 100644 --- a/notes-and-examples/2026.07.21/depth-first-search.md +++ b/notes-and-examples/2026.07.21/depth-first-search.md @@ -40,13 +40,7 @@ What about this one? 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: +Some starter questions: -``` - 0 --- 1 - | | - 3 --- 2 -``` - -- Arguments: starting node `0` -- Expected output: +- Could recursion help us here? +- What are some ways we can track already-visited nodes? What's the most *time-efficient* way to do so? diff --git a/notes-and-examples/2026.07.21/overview.md b/notes-and-examples/2026.07.21/overview.md index 3f3de60..ba3b6ee 100644 --- a/notes-and-examples/2026.07.21/overview.md +++ b/notes-and-examples/2026.07.21/overview.md @@ -1,3 +1,5 @@ ## 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. +To make our knowledge of graphs useful, we'll go over our first traversal method today: [depth-first search](./depth-first-search.md). We will also go over [breadth-first search](./breadth-first-search.md), and how both algorithms can be useful. + +Assignment: finish the code for depth-first search, and also implement breadth-first search.