Matthew Spillman's
Processing Projects

Breadth First Search Visualization

This is a demonstration of Breadth-First Search, a very common graph algorithm. A graph is a set of nodes/points connected by edges/lines. BFS is an algorithm which explores the graph from a source vertex until it has encountered every vertex which can been reached from the source. I made this as a project for Honors Data Structures and Algorithms, taught by Mitchell Griest at The Westminster Schools.

In a little more detail, here is how the algorithm works:

  1. First of all, the algorithm uses a coloring scheme to classify the nodes. A circle colored in white hasn't been discovered by the algorithm yet. A circle colored in gray has been discovered by the algorithm, but it might be connected to some other nodes which the algorithm hasn't discovered yet. A black circle has been investigated by the algorithm and is guaranteed to be connected to only black and gray circles. The goal of BFS is to discover every vertex which can be reached from the source vertex in a certain order, so we should expect that every vertex which can be reached from the source will be black once the search is complete.
  2. The algorithm initially colors all the vertices of the graph (the circles) white. Then, the source vertex from which the search will begin is colored gray.
  3. The algorithm picks a gray node called n. Then, it turns every white node which is connected to n into a gray node. It also colors the edge between n and that node blue. Finally, it colors n black, since it has guaranteed that n is no longer connected to any white (undiscovered) nodes.
  4. Step 3 is repeated until there are no more gray nodes. The blue edges identified by the algorithm comprise the edges of a "breadth-first tree", which you can see re-organized on the right. The path from the source vertex to any other vertex in the breadth-first tree represents the shortest path between those nodes.

AAAAAAAA