Skip to content
DSA Visualizerpreview

Depth-first search

Go as deep as you can before backing up; the call stack remembers the way back.

O(V + E) time · O(V) for the stack space

EdgesA-B, A-C, B-D, C-D, C-E, D-F, E-Ffrom A

Start a depth-first search at A. Numbers show the visiting order.

Graph with nodes A, B, C, D, E, F and edges A–B, A–C, B–D, C–D, C–E, D–F, E–F.
  • compare
  • swap or write
  • settled

1 / 24

Speed

Space play · ← → step · Home End jump · drag the strip to scrub