GF5: Breadth-first search

San Skulrattanakulchai

November 15, 2018

Background

Shortest Paths Problem

In general, given that \(V_0, \dots, V_{i-1}\) have been defined, we define \(V_i\) to be the set of all vertices \(v \in V\setminus (V_0 \cup \cdots \cup V_{i-1})\) such that there is some vertex \(u\in V_{i-1}\) with \(uv\in E\). We stop when \(V_i=\emptyset\).

BFS, high-level algorithm

BFS, low-level algorithm

Notes

  1. A BFS tree is a shortest-path tree, but not every shortest-path tree is a BFS tree.
  2. BFS is a natural algorithm for solving puzzles like Sam Lloyd’s 15-puzzle, River Crossing, etc.
  3. For each \(i\), let’s call the vertices in \(V_i\) vertices at level \(i\). The non-tree edges of the graph cannot skip forward any levels.