Reachability by Marking
Suppose we want to mark all the nodes in the graph which are reachable from a given node k.
Let G[1..n] be the adjacency list rep. of the graph
Let M[1..n] be the mark array, initially all falses.
void mark(int i)
M[i] = true;
x = G[i]
while (x != NULL) {
if (M[x->node] == false)
mark(G[x->node])
x = x->next
}
}
Previous slide
Next slide
Back to first slide
View graphic version