Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
Altered template type. Add: chapter, title. | Use this tool. Report bugs. | #UCB_Gadget |
||
(19 intermediate revisions by 15 users not shown) | |||
Line 1:
{{redirect-distinguish|Graph search|Facebook Graph Search}}
{{Short description|Computer science algorithm}}
{{refimprove|date=October 2014}}
In [[computer science]], '''graph traversal''' (also known as '''graph search''') refers to the process of visiting (checking and/or updating) each vertex in a [[Graph (discrete mathematics)|graph]]. Such traversals are classified by the order in which the vertices are visited. [[Tree traversal]] is a special case of graph traversal.
==Redundancy==
Unlike tree traversal, graph traversal may require that some vertices be visited more than once, since it is not necessarily known before transitioning to a vertex that it has already been explored. As graphs become more [[dense graph|dense]], this redundancy becomes more prevalent, causing computation time to increase; as graphs become more sparse, the opposite holds true.
Thus, it is usually necessary to remember which vertices have already been explored by the algorithm, so that vertices are
Several special cases of graphs imply the visitation of other vertices in their structure, and thus do not require that visitation be explicitly recorded during the traversal. An important example of this is a tree: during a traversal it may be assumed that all "ancestor" vertices of the current vertex (and others depending on the algorithm) have already been visited. Both the [[Depth-first search|depth-first]] and [[Breadth-first search|breadth-first graph searches]] are adaptations of tree-based algorithms, distinguished primarily by the lack of a structurally determined "root" vertex and the addition of a data structure to record the traversal's visitation state.
Line 13 ⟶ 14:
==Graph traversal algorithms==
Note. — If each vertex in a graph is to be traversed by a tree-based algorithm (such as DFS or BFS), then the algorithm must be called at least once for each [[connected component (graph theory)|connected component]] of the graph. This is easily accomplished by iterating through all the vertices of the graph, performing the algorithm on each vertex that is still unvisited when examined.
===Depth-first search===
Line 77 ⟶ 76:
==Graph exploration==
The problem of graph exploration can be seen as a variant of graph traversal. It is an [[Online algorithm|online problem]], meaning that the information about the graph is only revealed during the runtime of the algorithm. A common model is as follows: given a connected graph {{nowrap|1=''G'' = (''V'', ''E'')}} with non-negative edge weights. The algorithm starts at some vertex, and knows all incident outgoing edges and the vertices at the end of these edges—but not more. When a new vertex is visited, then again all incident outgoing edges and the vertices at the end are known. The goal is to visit all ''n'' vertices and return to the starting vertex, but the sum of the weights of the tour should be as small as possible. The problem can also be understood as a specific version of the [[travelling salesman problem]], where the salesman has to discover the graph on the go.
For general graphs, the best known algorithms for both undirected and directed graphs is a simple [[greedy algorithm]]:
* In the undirected case, the greedy tour is at most {{nowrap|''O''(ln ''n'')}}-times longer than an optimal tour.<ref>{{cite journal|last1=Rosenkrantz|first1=Daniel J.|last2=Stearns|first2=Richard E.|last3=Lewis, II|first3=Philip M.|title=An Analysis of Several Heuristics for the Traveling Salesman Problem|journal=SIAM Journal on Computing|volume=6|issue=3|pages=563–581|doi=10.1137/0206041|year=1977|s2cid=14764079 }}</ref> The best lower bound known for any deterministic online algorithm is
** Unit weight undirected graphs can be explored with a competitive ration of {{nowrap|2 − ''ε''}},<ref>{{cite journal |last1=Miyazaki |first1=Shuichi |last2=Morimoto |first2=Naoyuki |last3=Okabe |first3=Yasuo |title=The Online Graph Exploration Problem on Restricted Graphs |journal=IEICE Transactions on Information and Systems |date=2009 |volume=E92-D |issue=9 |pages=1620–1627 |doi=10.1587/transinf.E92.D.1620|bibcode=2009IEITI..92.1620M |hdl=2433/226939 |s2cid=8355092 |hdl-access=free }}</ref> which is already a tight bound on [[Tadpole graph|Tadpole graphs]].<ref>{{cite journal |last1=Brandt |first1=Sebastian |last2=Foerster |first2=Klaus-Tycho |last3=Maurer |first3=Jonathan |last4=Wattenhofer |first4=Roger |title=Online graph exploration on a restricted graph class: Optimal solutions for tadpole graphs |journal=Theoretical Computer Science |date=November 2020 |volume=839 |pages=176–185 |doi=10.1016/j.tcs.2020.06.007|arxiv=1903.00581 |s2cid=67856035 }}</ref>
* In the directed case, the greedy tour is at most ({{nowrap|''n'' − 1}})-times longer than an optimal tour. This matches the lower bound of {{nowrap|''n'' − 1}}.<ref>{{cite journal|last1=Foerster|first1=Klaus-Tycho|last2=Wattenhofer|first2=Roger|title=Lower and upper competitive bounds for online directed graph exploration|journal=Theoretical Computer Science|date=December 2016|volume=655|pages=15–29|doi=10.1016/j.tcs.2015.11.017|url=https://zenodo.org/record/895821|doi-access=free}}</ref> An analogous competitive lower bound of ''Ω''(''n'') also holds for randomized algorithms that know the coordinates of each node in a geometric embedding. If instead of visiting all nodes just a single "treasure" node has to be found, the competitive bounds are ''Θ''(''n''<sup>2</sup>) on unit weight directed graphs, for both deterministic and randomized algorithms.
==Universal traversal sequences==
{{expand section|date=December 2016}}
A ''universal traversal sequence'' is a sequence of instructions comprising a graph traversal for any [[regular graph]] with a set number of vertices and for any starting vertex. A probabilistic proof was used by Aleliunas et al. to show that there exists a universal traversal sequence with number of instructions proportional to {{nowrap|''O''(''n''<sup>5</sup>)}} for any regular graph with ''n'' vertices.<ref>{{cite
==See also==▼
* [[External memory graph traversal]]▼
==References==
{{reflist}}
{{Graph traversal algorithms}}
▲==See also==
{{Data structures and algorithms}}
▲* [[External memory graph traversal]]
[[Category:Graph algorithms]]
|