kids encyclopedia robot

Depth-first search facts for kids

Kids Encyclopedia Facts

In computer science, depth-first search (DFS) is a method used for traversing a graph. It starts at an arbitrary item of a graph and explores as far as possible along each branch before backtracking.

Depth-First-Search
Animated example of a depth-first search within a tree.

Implementation

Recursive

void depthFirstSearch(Item root) {
    if (root == null) return;
    root.found = true;
    for (Item neighbor : root.neighbors()) {
        if (!neighbor.found) depthFirstSearch(n);
    }
}

Related pages

See also

Kids robot.svg In Spanish: Búsqueda en profundidad para niños

kids search engine
Depth-first search Facts for Kids. Kiddle Encyclopedia.