Graph traversal

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. 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, 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 the depth-first and 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.

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

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's call stack via recursion) 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 then backtracks 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, including topological sorts and planarity testing.

Pseudocode

  • Input: A graph G and a vertex v of G.
  • Output: A labeling of the edges in the connected component of v as discovery edges and back edges.
procedure DFS(G, v) is
    label v as explored
    for all edges e in G.incidentEdges(v) do
        if edge e is unexplored then
            wG.adjacentVertex(v, e)
            if vertex w is unexplored then
                label e as a discovered edge
                recursively call DFS(G, w)
            else
               label e as a back edge

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

Pseudocode

  • Input: A graph G and a vertex v of G.
  • Output: The closest vertex to v satisfying some conditions, or null if no such vertex exists.
procedure BFS(G, v) is
    create a queue Q
    enqueue v onto Q
    mark v
    while Q is not empty do
        wQ.dequeue()
        if w is what we are looking for then
            return w
        for all edges e in G.adjacentEdges(w) do
            xG.adjacentVertex(w, e)
            if x is not marked then
                mark x
                enqueue x onto Q
    return null

Applications

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

Graph exploration

The problem of graph exploration can be seen as a variant of graph traversal. It is an 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 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 O(ln n)-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 of 2 − ε,[3] which is already a tight bound on Tadpole 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 of n − 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

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 O(n5) for any regular graph with n vertices.[6] The steps specified in the sequence are relative to the current node, not absolute. For example, if the current node is vj, and vj has d neighbors, then the traversal sequence will specify the next node to visit, vj+1, as the ith neighbor of vj, where 1 ≤ id.

See also

References

  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.

Read other articles:

Luki Hermawan Wakil Kepala BSSN ke-3Masa jabatan25 Februari 2022 – 27 Maret 2023 PendahuluSutantoPenggantiSuntanaWakil Kepala Lembaga Pendidikan dan Pelatihan PolriMasa jabatan1 Mei 2020 – 25 Februari 2022 PendahuluBoy Rafli AmarPenggantiEko Budi SampurnoKepala Kepolisian Daerah Jawa TimurMasa jabatan13 Agustus 2018 – 1 Mei 2020 PendahuluMachfud ArifinPenggantiMuhammad Fadil ImranWakil Kepala Badan Intelijen dan Keamanan PolriMasa jabatan2 Juni 2017 �...

 

Artikel ini membutuhkan rujukan tambahan agar kualitasnya dapat dipastikan. Mohon bantu kami mengembangkan artikel ini dengan cara menambahkan rujukan ke sumber tepercaya. Pernyataan tak bersumber bisa saja dipertentangkan dan dihapus.Cari sumber: Djanan Tajib – berita · surat kabar · buku · cendekiawan · JSTOR Djanan TajibDjanan Tajib (duduk), bersama Mr. Sunario, Mr. Sartono, Drs. Moh. Hatta, dan Mr. WirjonoNamaDjanan TajibAlma materUniversitas Al-Az...

 

Rumah Sakit Sultanah AminahHospital Sultanah AminahGeografiLokasiJohor Bahru, Johor, MalaysiaPelayananUnit Gawat DaruratYaSejarahDibuka1882Pranala luarSitus webhsajb.moh.gov.my/versibaru/DaftarRumah sakit di Malaysia Rumah Sakit Sultanah Aminah (HSA; Melayu: Hospital Sultanah Aminahcode: ms is deprecated ) adalah rumah sakit multi-spesialisasi yang didanai pemerintah yang terletak di Johor Bahru, Johor, Malaysia. Rumah sakit ini adalah rumah sakit terbesar di Johor dan rujukan utama dan pusat...

1630s conflict in New England Pequot WarPart of the American Indian WarsA 19th-century engraving depicting an incident in the Pequot WarDateJuly 1636 – September 1638LocationNew EnglandResult Pequot defeat and massacre Treaty of Hartford (1638)Belligerents Pequot tribe Massachusetts BayPlymouth Saybrook ConnecticutNarragansett tribeMohegan tribeCommanders and leaders Sachem Sassacus  Captain John UnderhillJohn MasonSachem UncasSagamore Wequash CookeSachem Miantonomoh vtePequot War Myst...

 

Untuk tempat lain yang bernama sama, lihat Sukadana (disambiguasi). SukadanaKecamatanPeta lokasi Kecamatan SukadanaSukadanaPeta lokasi Kecamatan SukadanaTampilkan peta KalimantanSukadanaSukadana (Indonesia)Tampilkan peta IndonesiaKoordinat: 1°14′14″S 109°56′58″E / 1.237165°S 109.949479°E / -1.237165; 109.949479Koordinat: 1°14′14″S 109°56′58″E / 1.237165°S 109.949479°E / -1.237165; 109.949479Negara IndonesiaProvinsiKa...

 

2014 Élections sénatoriales de 2020 en Charente 27 septembre 2020 Type d’élection Élections sénatoriales Postes à élire 2 sièges de sénateur Nicole Bonnefoy – PS Voix 673 60,58 %  François Bonneau – DVD Voix 512 46,08 %  Voix au 2e tour 593 54,11 %  Jérôme Royer – PS Voix 374 33,66 %  Voix au 2e tour 460 41,97 %  Jacques Chabot – UDI Voix 402 36,18 %  Sénateurs de la Charen...

2019 film InstinctFilm posterDirected byHalina ReijnWritten byEsther GerristenHalina ReijnProduced byFrans Van GestelArnold HeslenfeldLaurette SchillingsStarringCarice van HoutenMarwan KenzariEdited byJob Ter BurgMusic byElla Van Der WoudeProductioncompaniesTopkapi FilmsBNNVARAMan Up FilmDistributed byA24Release dates 12 August 2019 (2019-08-12) (Locarno) 3 October 2019 (2019-10-03) (Netherlands) Running time94 minutesCountryNetherlandsLanguageDutch Insti...

 

Pour les articles homonymes, voir King. Angus King Portrait officiel d'Angus King (2013). Fonctions Sénateur des États-Unis En fonction depuis le 3 janvier 2013(11 ans, 3 mois et 17 jours) Élection 6 novembre 2012 Réélection 6 novembre 2018 Circonscription Maine Législature 113e, 114e, 115e, 116e, 117e et 118e Groupe politique Démocrate Prédécesseur Olympia Snowe 72e gouverneur du Maine 5 janvier 1995 – 8 janvier 2003(8 ans et 3 jours) Élection 8 novembre...

 

Third race of the 2017 NASCAR Xfinity Series 2017 Boyd Gaming 300 Race details Race 3 of 33 in the 2017 NASCAR Xfinity SeriesDate March 11, 2017Official name 21st Annual Boyd Gaming 300Location North Las Vegas, Nevada, Las Vegas Motor SpeedwayCourse Permanent racing facility1.5 mi (2.41 km)Distance 200 laps, 300 mi (482.803 km)Scheduled Distance 200 laps, 300 mi (482.803 km)Average speed 118.525 miles per hour (190.747 km/h)Pole positionDriver Kyle Busch Joe Gibbs RacingTime 29.098Most l...

Disambiguazione – Se stai cercando il pittore cinquecentesco soprannominato Il Riccio, vedi Bartolomeo Neroni. Artista anonimo, medaglia di Andrea Briosco detto il Riccio, 1532 circa. Il Riccio, Satiro con calamaio, Metropolitan Museum Andrea Briosco, detto il Riccio e Crispo (Crispus) per la sua capigliatura folta e riccia (Trento, 1º aprile 1470 – Padova, 8 luglio 1532), è stato uno scultore italiano.[1] Indice 1 Biografia 2 Note 3 Bibliografia 4 Altri progetti 5 Collegamenti...

 

Interior Stadion Gelora Bung Karno di Jakarta, Indonesia. Stadion adalah sebuah bangunan yang umumnya digunakan untuk menyelenggarakan acara Olahraga, konser & kampanye politik, di mana di dalamnya terdapat lapangan atau pentas yang dikelilingi tempat berdiri atau duduk bagi penonton. Stadion tertua yang kita kenal adalah sebuah stadion di Olympia, Peloponnesos, Yunani yang telah menyelenggarakan Olimpiade Kuno sejak tahun 776 SM. Stadion umumnya digunakan untuk merujuk kepada bangunan ya...

 

 本表是動態列表,或許永遠不會完結。歡迎您參考可靠來源來查漏補缺。 潛伏於中華民國國軍中的中共間諜列表收錄根據公開資料來源,曾潛伏於中華民國國軍、被中國共產黨聲稱或承認,或者遭中華民國政府調查審判,為中華人民共和國和中國人民解放軍進行間諜行為的人物。以下列表以現今可查知時間為準,正確的間諜活動或洩漏機密時間可能早於或晚於以下所歸�...

Defensive fortification in Roman Britain Hadrian's WallThe location of Hadrian's Wall in what is now northern England, and the later Antonine Wall in what is now the Central Belt of ScotlandLocationNorthern EnglandCoordinates55°01′N 2°17′W / 55.017°N 2.283°W / 55.017; -2.283Length73 miles (117 km)BuiltBegun 122 ADBuilt forHadrianVisitors100,000+ annuallyGoverning bodyHistoric EnglandOwnerVarious private and public ownerships UNESCO World Heritage SiteDesig...

 

Untuk kegunaan lain, lihat Barus (disambiguasi). Perkampungan di Bukum, salah satu wilayah yang dibuka oleh marga Barus. Barus (Surat Batak Karo: ᯆᯒᯘᯬ᯳; disebut juga sebagai Karokaro Barus) adalah salah satu marga Batak Karo yang termasuk ke dalam induk marga Karokaro. Tokoh Beberapa tokoh yang bermarga Barus, di antaranya adalah: Bestari Barus Cerdas Barus Dipha Barus Donna Rosamayna Barus Referensi Artikel bertopik Batak ini adalah sebuah rintisan. Anda dapat membantu Wikipedia de...

 

Football match2020 FA Vase FinalWembley Stadium hosted the finalEvent2019–20 FA Vase Consett Hebburn Town 2 3 Date3 May 2021 (2021-05-03)VenueWembley Stadium, LondonAttendance0← 2019 2021 → The 2020 FA Vase Final was the 46th final of the Football Association's cup competition for teams at levels 9–11 of the English football league system. The match was contested between Consett and Hebburn Town. The final was finally played behind closed doors on 3 May 2021, a...

JKT48 SchoolLogo JKT48 SchoolGenreAcara varietasEdukasiBerdasarkanShukan AKB di TV TokyoPemeranJKT48Negara asal IndonesiaJmlh. episode8ProduksiProduser eksekutifVictor SetiawanProduserAnissa TisnadisastraDurasi30 menit (Minggu 14.30-15.00)Rumah produksiDentsu (JKT48 Project)AKSGTVDistributorMNC MediaRilis asliJaringanGlobal TVFormat gambar480i (SDTV)Rilis15 April 2012 –3 Juni 2012Acara terkaitKelas Internasional (NET., 2015—2017)Anak Sekolah (TRANS7, 2021—2023) JKT48 School a...

 

Statistics function For the phase-space function representing a quantum state, see Husimi Q representation. A plot of the Q-function. In statistics, the Q-function is the tail distribution function of the standard normal distribution.[1][2] In other words, Q ( x ) {\displaystyle Q(x)} is the probability that a normal (Gaussian) random variable will obtain a value larger than x {\displaystyle x} standard deviations. Equivalently, Q ( x ) {\displaystyle Q(x)} is the probability ...

 

赛珍珠 賽珍珠(攝於1972年)原文名稱Pearl Sydenstricker Buck出生Pearl Comfort Sydenstricker(1892-06-26)1892年6月26日 美国西維吉尼亞州希爾斯伯勒(英语:Hillsboro, West Virginia)逝世1973年3月6日(1973歲—03—06)(80歲) 美国佛蒙特州丹比(英语:Danby,Vermont)職業作家、教師國籍 美国教育程度康乃爾大學藝術創作碩士獎項普利策小说奖 1932 威廉·迪恩·豪威尔勋章(英语:William D...

Government school in Mphuti Street, Central Western Jabavu, SowetoMorris Isaacson High SchoolLocation1349 Mphuti Street, Central Western Jabavu, SowetoCoordinates26°14′44″S 27°52′20″E / 26.2455°S 27.8722°E / -26.2455; 27.8722InformationTypeGovernmentEstablished1956Colour(s)    Blue and White Morris Isaacson High School is a government secondary school in Soweto. Founded in 1956, the school took an important role at the start of the Soweto Uprisin...

 

この記事には複数の問題があります。改善やノートページでの議論にご協力ください。 出典は脚注などを用いて記述と関連付けてください。(2018年2月) 独自研究が含まれているおそれがあります。(2007年6月) 名古屋弁 名古屋弁番付表(秀松堂光楽・名古屋市中区)話される国 日本地域 名古屋市言語系統 日琉語族 日本語東日本方言東海東山方言岐阜・愛知方言尾�...