Chapter 5 · SimulationGraph Traversal? ← Chapter 5 Nodes Generate graph Start BFS DFS Cancel Speed SlowNormalFast visitedin queue / on stackReady. CloseGraph Traversal SimulatorAn undirected graph is generated and its nodes can be dragged. Breadth-first search (BFS) or depth-first search (DFS) then traverses the graph step by step.How to useEnter the number of nodes (2–20) and press Generate graph. Every pair of nodes is connected with probability 0.4, so the graph may be disconnected.Choose the Start node, then run BFS or DFS. Cancel stops the animation; Speed changes its pace.You can drag nodes with the mouse (or a finger) to tidy up the drawing, even while a traversal is running.Visited nodes are colored and numbered in visiting order; nodes waiting in the queue (BFS) or on the stack (DFS) are highlighted; tree edges show where each node was reached from. Neighbors are examined in increasing order.Breadth-first searchBFS uses a queue. Before moving to the next depth level it visits all the neighbors reachable at the moment, so the BFS tree contains shortest paths (in number of edges) from the start node. The time complexity is O(V + E).Depth-first searchDFS follows a stack-based strategy. It goes as deep as it can along one branch before backtracking. This demo uses an explicit stack: neighbors are pushed in reverse order so that the smallest neighbor is popped first, and a node counts as visited when it is popped. The time complexity is again O(V + E).Nodes that cannot be reached from the start node are never visited; the status line reports them.