Correctness of DFS [00MB]

How do we know that DFS does what we want? First of all, we need to argue that it won't go off into an inifinite loop or infinite recursion.

There are many things we could prove about DFS—indeed, DFS has a lot of nice properties that can be used for all sorts of purposes which we sadly don't have time to talk about—but the most basic one is that DFS discovers which vertices are connected and which are not.

Context

Depth-first search (DFS) [00M6]

Related

Algorithm. DFS (version 1) [00M8]