Graph Theory37 sections · 1633 units
Open in Course

Visualizing the Trace

Dry Run

Graph: 121−2, 131−3, 242−4. Start dfs(11):

1.1. Mark 11. List: {22, 33}.

2.2. Go to 22.

Call dfs(22). 2.12.1 Mark 22. List: {11, 44}. 2.22.2 Neighbor 11 is visited. Skip. 2.32.3 Neighbor 44 is not. Call dfs(44). 2.3.12.3.1 Mark 44. List: {22}. 2.3.22.3.2 Neighbor 22 is visited. Skip. 2.3.32.3.3 Done. Return to dfs(22). 2.42.4 dfs(22) Done. Return to dfs(11).

3.3. Back at 11.

Next neighbor is 33. Call dfs(33). Path: 124back31→2→4…back⋯→3.