CS 411 Fall 2025 > Outline & Supplemental Notes for September 15, 2025
CS 411 Fall 2025
Outline & Supplemental Notes
for September 15, 2025
Outline
Exhaustive Search [L 3.4]
- Terminology
- Combinatorial problem: problem related to combinations, orderings, subsets. Graph problems are a closely related category.
- A instance of a problem is the specific input an algorithm would get. For example, an instance of the sorting problem would be a list of items to sort.
- Exhaustive search:
look at all parts of a solution space.
- We generally only use the term when the solution space (a.k.a. search space) is interesting in some way or tricky to search. This is often true with combinatorial or graph problems. Thus, exhaustive search is essentially the application of brute-force techniques to such problems.
- Combinatorial explosion: often extremely poor performance as problems get larger
- Example Problems
- TSP
- Knapsack Problem
Depth-First Search & Breadth-First Search [L 3.5]
- Search spaces & graphs
- Graph representations
- Adjacency matrix
- Adjacency lists
- Depth-First Search (DFS)
- What it is.
- Recursive & non-recursive formulations. See Supplemental Notes.
- Applications: connectedness.
- Alternate ordering: order that vertices in DFS algorithm become dead ends.
- Breadth-First Search (BFS)
- What it is.
- Applications: connectedness, minimum-edge paths.
- Change Stack in DFS to Queue.
Supplemental Notes
The text describes DFS as a recursive algorithm. As with all recursive algorithms, we can reformulate it in a non-recursive form by using our own stack. With DFS this is both easy and instructive.
A non-recursive DFS is essentially as follows.
- Push the start vertex.
- Repeat as long as the stack is empty:
- Pop off the vertex on the top of the stack.
- If this vertex is unvisited, then visit it and push all of its unvisited neighbors.
Notes
- The above algorithm is nicest when the loop that pushes unvisited neighbors goes through the vertices in reverse order. This means that low-numbered vertices are popped first.
- As with the recursive DFS algorithm in the text, the above works only for a connected graph, and a more general DFS is obtained by iterating through the vertices of the graph, calling the above algorithm with each vertex as the start vertex.
The above algorithm can be turned into a BFS simply by changing the stack to a queue. When we do this, we generally want to push (enqueue) the unvisited neighbors in forward order.