Skip to content
depth-first search

File:Depth-first-tree.svg · Wikimedia Commons · See Wikimedia Commons

EntityQ816319· pop 42· linked from 194 articles

depth-first search

Sign in to save

Also known as DFS, depth-first traversal, depth first search

algorithm for traversing or searching tree or graph data structures

Key facts

Class
Search algorithm
Data structure
Graph
Worst case performance
O ( | V | + | E | ) {\displaystyle O(|V|+|E|)} for explicit graphs traversed without repetition, O ( b d ) {\displaystyle O(b^{d})} for implicit graphs with branching factor b searched to depth d
Worst case space complexity
O ( | V | ) {\displaystyle O(|V|)} if entire graph is traversed without repetition, O(longest path length searched) = O ( b d ) {\displaystyle O(bd)} for implicit graphs without elimination of duplicate nodes
Optimal
no (does not generally find shortest paths)

via Wikipedia infobox

Described at

Depth first search - Wikimedia Commons

commons.wikimedia.org

Link to a page describing this subject · 937 chars · not written by Vinony

Wikidata facts

Image
Depth-first-tree.svg
Show 4 more facts
Commons category
Depth-first search
short name
DFS
Commons gallery
Depth first search
Sources (2)

via Wikidata · CC0

~12 min read

Article

Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible along each branch before backtracking. Extra memory, usually a stack, is needed to keep track of the nodes discovered so far along a specified branch which helps in backtracking of the graph.

A version of depth-first search was investigated in the 19th century by French mathematician Charles Pierre Trémaux as a strategy for solving mazes.

Gallery (5)

Connections

Categories