Note
For a good gaming experience of the games in the course, we recommend using a desktop or a laptop computer rather than a tablet or smartphone.
Breadth-First Search Algorithm Game
In this game, the player can enter a graph in the form of vertices and their comma-separated neighbors, and select a start vertex. Then, they can click the “Start” button to apply the Breadth-First Search (BFS) algorithm. The visited vertices in the order they are visited are displayed as colored boxes below the button.
The graph input is represented using an HTML table. The player can edit the values in the cells of the table to define the vertices and their neighbors.
The Node class represents a vertex in the graph with its neighbors and visited status.
The bfs function performs the BFS algorithm on the input graph and returns an array containing the visited vertices in the order they are visited.
Vertex | Neighbours (comma-separated) |
---|---|
A | B,C |
B | A,D,E |
C | A,F,G |
D | B |
E | B,F |
F | C,E |
G | C |