Nepedia
Back to Discover
Independent Reader
🔢

Depth-first search

math Maturity 7-9 Next article →

Imagine you are exploring a deep cave. You pick one tunnel and walk as far as you can.

Depth-First-Search
Depth-First-Search

If you hit a dead end, you turn back. You go back to the last place where you had a choice. This way of searching is called depth-first search. It is a set of steps used to explore shapes called graphs. A graph is a group of points connected by lines.

To keep track of where it has been, the search uses a stack. A stack is a way to store items in a pile. This helps the search know how to backtrack. In the 1800s, a man named Charles Pierre Trémaux studied this. He used it as a way to solve mazes.

Computers use this to look through many things. They might use it to search the web. Sometimes, the web is too big to see all at once. In those cases, the search only goes to a certain depth. This means it only goes so far into a branch before stopping. This saves memory and space.

graph.traversal.example
graph.traversal.example

Scientists also use this to study how living things are related. It helps them build trees that show how species change over time.

200 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (6)
File:Depth-First-Search.gif
Depth-First-Search.gif
File:graph.traversal.example.svg
graph.traversal.example.svg
File:Tree edges.svg
Tree edges.svg
File:If-then-else-control-flow-graph.svg
If-then-else-control-flow-graph.svg
File:Graph.traversal.example.svg
Graph.traversal.example.svg
MAZE 30x20 DFS.ogv
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.