6 views

Uploaded by HarshitShukla

DFS

- Subgraphs Depth-First Search
- ADA-Unit 1
- A new algorithm for finding minimum spanning trees with undirected neutrosophic graphs
- dfs
- Odd Harmonious Labeling of Some Graphs
- DFS academic text for reference
- DFS
- DFS
- ai
- Data Structure
- Graph-Theoretic Scagnostics
- HW10
- Chapter 3 - Greedy Method
- Theory of Computer Science
- Data Structures
- graphtheory.pdf
- Lab 8
- Searches in AI
- uninformed search.pdf
- Digraphs.docx

You are on page 1of 19

and M. H. Goldwasser, Wiley, 2014

Depth-First Search

A

B D E

Depth-First Search 1

Subgraphs

A subgraph S of a graph G

is a graph such that

The vertices of S are a subset

of the vertices of G

The edges of S are a subset Subgraph

of the edges of G

A spanning subgraph of G

is a subgraph that

contains all the vertices of

G

Spanning subgraph

Depth-First Search 2

Connectivity

A graph is connected

if there is a path

between every pair

of vertices Connected graph

A connected

component of a

graph G is a maximal

connected subgraph

of G

Non connected graph with two

connected components

Depth-First Search 3

Trees and Forests

A (free) tree is an

undirected graph T such

that

T is connected

T has no cycles

from the one of a rooted tree

A forest is an undirected

graph without cycles

The connected

components of a forest

are trees

Forest

Depth-First Search 4

Spanning Trees and Forests

A spanning tree of a

connected graph is a

spanning subgraph that is a

tree

A spanning tree is not

unique unless the graph is a

tree Graph

Spanning trees have

applications to the design of

communication networks

A spanning forest of a

graph is a spanning

subgraph that is a forest

Spanning tree

2014 Goodrich, Tamassia, Goldwasser

Depth-First Search 5

Depth-First Search

Depth-first search (DFS) DFS on a graph with n

is a general technique vertices and m edges

for traversing a graph takes O(nm ) time

A DFS traversal of a DFS can be further

Visits all the vertices and graph problems

edges of G Find and report a path

Determines whether G is between two given vertices

connected Find a cycle in the graph

Computes the connected Depth-first search is to

components of G

Computes a spanning forest graphs what Euler tour is

of G to binary trees

Depth-First Search 6

DFS Algorithm from a Vertex

Depth-First Search 7

Java Implementation

Depth-First Search 8

Example

A

A unexplored vertex

A visited vertex

B D E

unexplored edge

discovery edge C

back edge

A A

B D E B D E

C C

Depth-First Search 9

Example (cont.)

A A

B D E B D E

C C

A A

B D E B D E

C C

Depth-First Search 10

DFS - Iterative

DFS-Iterative(G,v):

let S be a stack

S.push(v)

while S is not empty

v = S.pop()

if v is not labeled as discovered:

label v as discovered

For edges from v to w G.adjacentEdges(v) do

S.push(w)

Depth-First Search 11

DFS and Maze Traversal

The DFS algorithm is

similar to a classic

strategy for exploring

a maze

We mark each

intersection, corner and

dead end (vertex) visited

We mark each corridor

(edge ) traversed

We keep track of the

path back to the

entrance (start vertex) by

means of a rope

(recursion stack)

Depth-First Search 12

Properties of DFS

Property 1

DFS(G, v) visits all the

vertices and edges in the

connected component of v A

Property 2

The discovery edges

B D E

labeled by DFS(G, v) form

a spanning tree of the

connected component of v

C

Depth-First Search 13

Analysis of DFS

Setting/getting a vertex/edge label takes O(1) time

Each vertex is labeled twice

once as UNEXPLORED

once as VISITED

Each edge is labeled twice

once as UNEXPLORED

once as DISCOVERY or BACK

Method incidentEdges is called once for each vertex

DFS runs in O(n m) time provided the graph is

Recall that v deg(v) 2m

Depth-First Search 14

Path Finding

We can specialize the DFS

algorithm to find a path Algorithm pathDFS(G, v, z)

setLabel(v, VISITED)

between two given vertices S.push(v)

u and z using the template if v z

method pattern return S.elements()

We call DFS(G, u) with u as for all e G.incidentEdges(v)

if getLabel(e) UNEXPLORED

the start vertex w opposite(v,e)

We use a stack S to keep if getLabel(w)

track of the path between UNEXPLORED

the start vertex and the setLabel(e,

DISCOVERY)

current vertex S.push(e)

As soon as destination pathDFS(G, w, z)

vertex z is encountered, we S.pop(e)

return the path as the else

setLabel(e, BACK)

contents of the stack S.pop(v)

Depth-First Search 15

Path Finding in Java

Depth-First Search 16

Cycle Finding

Algorithm cycleDFS(G, v, z)

We can specialize the DFS setLabel(v, VISITED)

algorithm to find a simple S.push(v)

for all e G.incidentEdges(v)

cycle using the template if getLabel(e) UNEXPLORED

method pattern w opposite(v,e)

S.push(e)

We use a stack S to keep if getLabel(w) UNEXPLORED

track of the path between setLabel(e, DISCOVERY)

pathDFS(G, w, z)

the start vertex and the S.pop(e)

else

current vertex T new empty stack

As soon as a back edge repeat

o S.pop()

(v, w) is encountered, we T.push(o)

until o w

return the cycle as the return T.elements()

portion of the stack from S.pop(v)

the top to vertex w

Depth-First Search 17

DFS for an Entire Graph

The algorithm uses a mechanism

for setting and getting labels of Algorithm DFS(G, v)

vertices and edges Input graph G and a start vertex v of

Algorithm DFS(G) G

Input graph G Output labeling of the edges of G

Output labeling of the edges of in the connected component of

G v

as discovery edges and as discovery edges and back

back edges edges

for all u G.vertices() setLabel(v, VISITED)

setLabel(u, UNEXPLORED) for all e G.incidentEdges(v)

for all e G.edges() if getLabel(e) UNEXPLORED

setLabel(e, UNEXPLORED) w opposite(v,e)

for all v G.vertices() if getLabel(w)

if getLabel(v) UNEXPLORED

UNEXPLORED setLabel(e, DISCOVERY)

DFS(G, v) DFS(G, w)

else

setLabel(e, BACK)

2014 Goodrich, Tamassia, Goldwasser

Depth-First Search 18

All Connected Components

Loop over all vertices, doing a DFS from

each unvisted one.

Depth-First Search 19

- Subgraphs Depth-First SearchUploaded bynautilus_261
- ADA-Unit 1Uploaded byapi-3723664
- A new algorithm for finding minimum spanning trees with undirected neutrosophic graphsUploaded byAnonymous 0U9j6BLllB
- dfsUploaded bymuucool
- Odd Harmonious Labeling of Some GraphsUploaded byDon Hass
- DFS academic text for referenceUploaded byAnkur Singh
- DFSUploaded byLalith Kartikeya
- DFSUploaded byLucian Rodjan
- aiUploaded bySanthosh Naidu
- Data StructureUploaded byNeeraj Joshi
- Graph-Theoretic ScagnosticsUploaded bylgallindo
- HW10Uploaded byClaire
- Chapter 3 - Greedy MethodUploaded byMhiie Jelaine
- Theory of Computer ScienceUploaded byvishaldream
- Data StructuresUploaded bykark437
- graphtheory.pdfUploaded byrps
- Lab 8Uploaded byMankush Jain
- Searches in AIUploaded bybadboy Nanu
- uninformed search.pdfUploaded byabhishek reddy
- Digraphs.docxUploaded byKarthik Nair
- Appendix_Glossary of Graph Theory - WiktionaryUploaded bymars
- Text RankUploaded byDiana Kate
- Play With TreesUploaded byLippyHeart
- Data Modeling TechniquesUploaded byRom
- Chap 8Uploaded byArpit Goyal
- %%%%%Degree Distribution and Hopcount InWireless Ad-Hoc NetworksUploaded byHussein Elattar
- optUploaded byRoyalRächer
- Kouki Taniyama and Akira Yasuhara- Clasp-pass moves on knots, links and spatial graphsUploaded byMopadDeluxe
- DataStructures_material.docxUploaded byuma s
- Further Mathematics SL - Nov 2001 - P2 $Uploaded bykhey

- YG Core Competency FrameworkUploaded byHarshitShukla
- Onboarding - FAQ'sUploaded byHarshitShukla
- Study and Practice of Yoga Volume-IUploaded byHarshitShukla
- Yoga of Knowledge Pandit M.P.Uploaded byHarshitShukla
- Deep Learning LibUploaded byrakikira
- computer-science-major-worksheet-2016-17.pdfUploaded byHarshitShukla
- Srimad-Bhagvatam.pdfUploaded bymonasha
- Glimpses of Vedic LiteratureUploaded byHarshitShukla
- Presentation (1)Uploaded byHarshitShukla
- presentation (1).pdfUploaded byHarshitShukla
- Dem128064f Fgh PwUploaded byHarshitShukla
- InterOP_TestReportUploaded byHarshitShukla
- Fgh Global 141104 EnglishUploaded byHarshitShukla
- 130559.full.pdfUploaded byHarshitShukla
- Teaching-Philosophy-Guidelines.pdfUploaded byHarshitShukla
- eDTP_instructions_1_2.pdfUploaded byHarshitShukla
- 13494T 2017IF USA-CAN Wild West Cowboys and Buffalos STD EDTPUploaded byHarshitShukla
- IRCP-Policies-Pic-4-3-16.pdfUploaded byHarshitShukla
- Retiree_Tuition_Benefit.pdfUploaded byHarshitShukla
- 1york-yhe-5005747-ytg-a-0216Uploaded byHarshitShukla
- lec07-dfsbfsUploaded byHarshitShukla
- _528195-ytg-a-0609Uploaded byHarshitShukla
- 251933-YTG-J-1009SunlineXPUploaded byHarshitShukla
- Modern Placer MiningUploaded byHarshitShukla
- ytg.pdfUploaded byHarshitShukla
- Mcbee v Gy YhrbaUploaded byHarshitShukla
- Manual Chiller York Model Ytg 5Uploaded byHarshitShukla
- Manual Chiller York Model Ytg 3Uploaded byHarshitShukla
- Manual Chiller York Model Ytg 6Uploaded byHarshitShukla

- Fat TriangleUploaded byKarthik Sheshadri
- Energy Efficient Power Failure Diagonisis For Wireless Network Using Random Graph TheoryUploaded byidescitation
- Small WorldUploaded bythylaberes
- Graph Theory and Its Applications to Problems of SocietyUploaded byT Sai Teja
- Dominating Sets and Spanning Tree based Clustering Algorithms for Mobile Ad hoc NetworksUploaded byEditor IJACSA
- CSI-2110-summary.pdfUploaded byjohn
- D1 NotesUploaded byAlisha Thomas
- Finite State AutomataUploaded byTanupriya Chaubey
- Psychnology Journal 4 1 MartinoUploaded bySarra Moneir
- LeoUploaded byActivamedia Web
- Pipe Network Analysis, By Mun-fong Lee, University of Florida, 1983, Fortran ProgramUploaded byJorGitop LUje
- ACSL-GraphTheoryUploaded byPKDianna
- 10.1.1.43.2908Uploaded byjimakosjp
- ProblemsUploaded byDhilip Prabakaran
- Graph Theory by Tero HarjuUploaded byabelous
- Some Properties on Strong Roman Domination in GraphsUploaded byEditor IJRITCC
- AN APPLICATION OF Gd-METRIC SPACES AND METRIC DIMENSION OF GRAPHSUploaded byMegan Bell
- Ch5Uploaded byjackaccyou
- Intelligent Information and Advising SystemUploaded byAli Ghalehban - علی قلعه بان
- "SPLIT AND NON SPLIT TWO DOMINATION NUMBERS OF SEMI TOTAL - POINT GRAPH"Uploaded byAnonymous vQrJlEN
- DAA Privious Gate-FinalUploaded byArpkeet IJ
- 15 Spectral AnalysisUploaded bymorgoth12
- network analysis (1).pdfUploaded byAnnisa Salsabilla
- r2013 Cse Vii Cs6702 Gta QbankUploaded byPadma Naban
- total domination books.pdfUploaded byGuru Viswanathan
- GetPDFServletUploaded byDalibor Petkovic
- Operations Research.pdfUploaded byShahid Naseem
- C. Vasudev - Combinatorics and Graph Theory - New Age - 577pUploaded bySeidKršić
- A Study of Vertex Edge Coloring Techniques With ApplicationUploaded byIjcemJournal
- Assignment QuestionsUploaded byWendoor6696