CS 112b
Spring 2000
Ileana Streinu

CS 112
Depth-First Search


void DFS(Graph G, int v)
{
// v is the index of the start node
// but you can implement it with a pointer instead

if ( v has already been visited) return;
else visit v; //e.g. print it

for (each node u in the list of neighbors of v)
{
DFS(G, u);
}
return;
}

Ileana Streinu