Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Graph traversal

From Wikipedia, the free encyclopedia
(Redirected fromGraph exploration algorithm)
"Graph search" redirects here and is not to be confused withFacebook Graph Search.
Computer science algorithm
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Graph traversal" – news ·newspapers ·books ·scholar ·JSTOR
(October 2014) (Learn how and when to remove this message)

Incomputer science,graph traversal (also known asgraph search) refers to the process of visiting (checking and/or updating) each vertex in agraph. Such traversals are classified by the order in which the vertices are visited.Tree traversal is a special case of graph traversal.

Redundancy

[edit]

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 moredense, 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 revisited as infrequently as possible (or in the worst case, to prevent the traversal from continuing indefinitely). This may be accomplished by associating each vertex of the graph with a "color" or "visitation" state during the traversal, which is then checked and updated as the algorithm visits each vertex. If the vertex has already been visited, it is ignored and the path is pursued no further; otherwise, the algorithm checks/updates the vertex and continues down its current path.

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 thedepth-first andbreadth-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.

Graph traversal algorithms

[edit]

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 eachconnected 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

[edit]
Main article:Depth-first search

A depth-first search (DFS) is an algorithm for traversing a finite graph. DFS visits the child vertices before visiting the sibling vertices; that is, it traverses the depth of any particular path before exploring its breadth. A stack (often the program'scall stack viarecursion) is generally used when implementing the algorithm.

The algorithm begins with a chosen "root" vertex; it then iteratively transitions from the current vertex to an adjacent, unvisited vertex, until it can no longer find an unexplored vertex to transition to from its current location. The algorithm thenbacktracks along previously visited vertices, until it finds a vertex connected to yet more uncharted territory. It will then proceed down the new path as it had before, backtracking as it encounters dead-ends, and ending only when the algorithm has backtracked past the original "root" vertex from the very first step.

DFS is the basis for many graph-related algorithms, includingtopological sorts andplanarity testing.

Pseudocode

[edit]
  • Input: A graphG and a vertexv ofG.
  • Output: A labeling of the edges in the connected component ofv as discovery edges and back edges.
procedure DFS(G,v)is    labelv as exploredfor all edgese inG.incidentEdges(v)doif edgee is unexploredthenwG.adjacentVertex(v,e)if vertexw is unexploredthen                labele as a discovered edge                recursively call DFS(G,w)else               labele as a back edge

Breadth-first search

[edit]
Main article:Breadth-first search
[icon]
This sectionneeds expansion. You can help byadding to it.(October 2012)

A breadth-first search (BFS) is another technique for traversing a finite graph. BFS visits the sibling vertices before visiting the child vertices, and aqueue is used in the search process. This algorithm is often used to find the shortest path from one vertex to another.

Pseudocode

[edit]
  • Input: A graphG and a vertexv ofG.
  • Output: The closest vertex tov satisfying some conditions, or null if no such vertex exists.
procedure BFS(G,v)is    create a queueQ    enqueuev ontoQ    markvwhileQ is not emptydowQ.dequeue()ifw is what we are looking forthen            returnwfor all edgese inG.adjacentEdges(w)doxG.adjacentVertex(w,e)ifx is not markedthen                markx                enqueuex ontoQreturn null

Applications

[edit]

Breadth-first search can be used to solve many problems in graph theory, for example:

Graph exploration

[edit]

The problem of graph exploration can be seen as a variant of graph traversal. It is anonline 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 graphG = (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 alln 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 thetravelling 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 simplegreedy algorithm:

  • In the undirected case, the greedy tour is at mostO(lnn)-times longer than an optimal tour.[1] The best lower bound known for any deterministic online algorithm is 10/3.[2]
    • Unit weight undirected graphs can be explored with a competitive ration of2 −ε,[3] which is already a tight bound onTadpole graphs.[4]
  • In the directed case, the greedy tour is at most (n − 1)-times longer than an optimal tour. This matches the lower bound ofn − 1.[5] 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Θ(n2) on unit weight directed graphs, for both deterministic and randomized algorithms.

Universal traversal sequences

[edit]
[icon]
This sectionneeds expansion. You can help byadding to it.(December 2016)

Auniversal traversal sequence is a sequence of instructions comprising a graph traversal for anyregular 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 toO(n5) for any regular graph withn vertices.[6] The steps specified in the sequence are relative to the current node, not absolute. For example, if the current node isvj, andvj hasd neighbors, then the traversal sequence will specify the next node to visit,vj+1, as theith neighbor ofvj, where 1 ≤id.

See also

[edit]

References

[edit]
  1. ^Rosenkrantz, Daniel J.; Stearns, Richard E.; Lewis, II, Philip M. (1977). "An Analysis of Several Heuristics for the Traveling Salesman Problem".SIAM Journal on Computing.6 (3):563–581.doi:10.1137/0206041.S2CID 14764079.
  2. ^Birx, Alexander; Disser, Yann; Hopp, Alexander V.; Karousatou, Christina (May 2021). "An improved lower bound for competitive graph exploration".Theoretical Computer Science.868:65–86.arXiv:2002.10958.doi:10.1016/j.tcs.2021.04.003.S2CID 211296296.
  3. ^Miyazaki, Shuichi; Morimoto, Naoyuki; Okabe, Yasuo (2009). "The Online Graph Exploration Problem on Restricted Graphs".IEICE Transactions on Information and Systems. E92-D (9):1620–1627.Bibcode:2009IEITI..92.1620M.doi:10.1587/transinf.E92.D.1620.hdl:2433/226939.S2CID 8355092.
  4. ^Brandt, Sebastian; Foerster, Klaus-Tycho; Maurer, Jonathan; Wattenhofer, Roger (November 2020). "Online graph exploration on a restricted graph class: Optimal solutions for tadpole graphs".Theoretical Computer Science.839:176–185.arXiv:1903.00581.doi:10.1016/j.tcs.2020.06.007.S2CID 67856035.
  5. ^Foerster, Klaus-Tycho; Wattenhofer, Roger (December 2016)."Lower and upper competitive bounds for online directed graph exploration".Theoretical Computer Science.655:15–29.doi:10.1016/j.tcs.2015.11.017.
  6. ^Aleliunas, R.; Karp, R.; Lipton, R.; Lovász, L.; Rackoff, C. (1979). "Random walks, universal traversal sequences, and the complexity of maze problems".20th Annual Symposium on Foundations of Computer Science (SFCS 1979):218–223.doi:10.1109/SFCS.1979.34.S2CID 18719861.
Graph andtree traversal algorithms
Search
Shortest path
Minimum spanning tree
Data structures
Algorithms andalgorithmic paradigms
Retrieved from "https://en.wikipedia.org/w/index.php?title=Graph_traversal&oldid=1250833600"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp