6 views

Uploaded by Aditya SanjayBoob

Depth-first search is an algorithm for traversing or searching tree or graph data structures. One starts at the root and explores as far as possible along each branch before backtracking

- cp1.pdf
- Homework 2 Theory Write-up
- Assign 1
- Back Tracking1
- HW1
- 42 Directed Graphs
- Graph Theory (1)
- אלגוריתמים- הרצאה 5 | DFS, Topological Sort and Strongly Connected Components
- 10.1.1.154
- Single Valued Neutrosophic Signedgraphs
- GNotes
- On Signed Graphs Whose Two Path Signed Graphs are Switching Equivalent to Their Jump Signed Graphs
- MIT6 006F11 Quiz2 Sol
- Search 041005
- Single Valued Neutrosophic Signed Graphs
- Or Notes 2017a
- Differential+Equation+[Practice+Question].pdf
- Binomial+Theorem+[Practice+Question].pdf
- Exercise+1(A,B,C).pdf
- Determinants+[Practice+Question].pdf

You are on page 1of 6

Lecture Overview

• Depth-First Search

• Edge Classification

• Cycle Testing

• Topological Sort

Recall:

• graph search: explore a graph

e.g., find a path from start vertex s to a desired vertex

• adjacency lists: array Adj of |V | linked lists

– for each vertex u ∈ V , Adj[u] stores u’s neighbors, i.e., {v ∈ V | (u, v) ∈ E}

(just outgoing edges if directed)

For example:

a

b

c

a

c

b

c

c

b

Adj

Figure 1: Adjacency Lists

**Breadth-first Search (BFS):
**

Explore level-by-level from s — find shortest paths

1

a

Adj) parent = { } for s in V: if s not in parent: parent [s] = None DFS-visit (V.Depth-First Search (DFS) This is like exploring a maze. s Figure 2: Depth-First Search Frontier Depth First Search Algorithm • follow path until you get stuck • backtrack along breadcrumbs until reach unexplored neighbor • recursively explore • careful not to repeat a vertex } parent = {s: None} DFS-visit (V. Adj. Adj. s): start for v in Adj [s]: if v not in parent: v parent [v] = s finish DFS-visit (V. s) } search from start vertex s (only see stuff reachable from s) explore entire graph (could do same to extend BFS) Figure 3: Depth-First Search Algorithm 2 . v) v DFS (V. Adj.

mark nodes for duration they are “on the stack” • only tree and back edges in undirected graph Analysis • DFS-visit gets called withX a vertex s only once (because then parent[s] set) =⇒ time in DFS-visit = |Adj[s]| = O(E) s∈V • DFS outer loop adds just O(V ) =⇒ O(V + E) time (linear time) 3 .Example S1 forward edge 1 a b 5 c 2 4 back edge 8 d 3 cross edge S2 6 f e 7 back edge Figure 4: Depth-First Traversal Edge Classification tree edges (formed by parent) nontree edges back edge: to ancestor forward edge: to descendant cross edge (to another subtree) Figure 5: Edge Classification • to compute this classification (back or not).

where vertices represent tasks & edges represent dependencies. will see (vk . order tasks without violating dependencies 4 . v0 ) as back edge Job scheduling Given Directed Acylic Graph (DAG). will visit vi+1 (& finish): will consider edge (vi . vi+1 ) =⇒ visit vi+1 now or already did • =⇒ before visit to v0 finishes.Cycle Detection Graph G has a cycle ⇔ DFS has a back edge Proof (<=) tree edges is a cycle back edge: to tree ancestor (=>) consider first visit to cycle: v3 v2 vk v1 v0 FIRST! • before visit to vi finishes. will visit vk (& didn’t before) • =⇒ before visit to vk (or v0 ) finishes.

C..reverse() . CF ← slow .G.8 G H 7 I 4 A 9 2 3 C B D F 1 E 6 5 Figure 6: Dependence Graph: DFS Finishing Times Source: Source = vertex with no incoming edges = schedulable at beginning (A. BE.I) Attempt: BFS from each source: • from A finds A.. F • from D finds D. BH.append(v) order. and wrong! • from G finds G. . order. H • from I finds I Topological Sort Reverse of DFS finishing times (time at which DFS-Visit(v) finishes) 5 DFS-Visit(v) . .

. i. will visit v (via (u.Correctness For any edge (u. v finished before u u v • if u visited before v: – before visit to u finishes. v) — u ordered before v. v) or otherwise) – =⇒ v finishes before u • if v visited before u: – graph is acyclic – =⇒ u cannot be reached from v – =⇒ visit to v finishes before visiting u 6 .e.

- cp1.pdfUploaded byNicu Mih
- Homework 2 Theory Write-upUploaded byDaniel 'Danger' Colson
- Assign 1Uploaded byZulqarnayn
- Back Tracking1Uploaded byRishabh Upadhyay
- HW1Uploaded byrareninjaboy
- 42 Directed GraphsUploaded byRavi Sankar
- Graph Theory (1)Uploaded byDhoorjati Vommi
- אלגוריתמים- הרצאה 5 | DFS, Topological Sort and Strongly Connected ComponentsUploaded byRon
- 10.1.1.154Uploaded byshushruthaa
- Single Valued Neutrosophic SignedgraphsUploaded byMia Amalia
- GNotesUploaded byMizanur Rahman
- On Signed Graphs Whose Two Path Signed Graphs are Switching Equivalent to Their Jump Signed GraphsUploaded byDon Hass
- MIT6 006F11 Quiz2 SolUploaded byJaspreet Kaur
- Search 041005Uploaded byRaghad Al-Shabani
- Single Valued Neutrosophic Signed GraphsUploaded byMia Amalia

- Or Notes 2017aUploaded byAditya SanjayBoob
- Differential+Equation+[Practice+Question].pdfUploaded byAditya SanjayBoob
- Binomial+Theorem+[Practice+Question].pdfUploaded byAditya SanjayBoob
- Exercise+1(A,B,C).pdfUploaded byAditya SanjayBoob
- Determinants+[Practice+Question].pdfUploaded byAditya SanjayBoob
- Application+of+Derivative+_Tangent+&+Normal,+Monotonicity,+Maxima-minima_-[Practice+Question].pdfUploaded byAditya SanjayBoob
- 3+Dimensional+Cood.+Geometry+[Practice+Question].pdfUploaded byAditya SanjayBoob
- Alkane.pdfUploaded byAditya SanjayBoob
- Area+Under+the+curve+[Practice+Question].pdfUploaded byAditya SanjayBoob
- Alkyl+Halide.pdfUploaded byAditya SanjayBoob

- 1-s2.0-S113848911400017X-main.pdfUploaded byBenjamin Naula
- The Reliability of a Two-item ScaleUploaded byRadzi Fasha
- Math119 Test3 Study Guide Part1Uploaded byQuy An
- Sem.org IMAC XXII Conf s24p07 Evaluation Rotating Driveshaft Breathing Mode With Nearfield AcousticUploaded byCyberAxE
- ColumbiaUploaded byFirdaus Abd Malek
- Absenteeism of the Workers of the Kerala Balers Private Limited, Alappuzha.Uploaded byAmeen Mt
- format for_Preparation_of_mid term and end term report.pdfUploaded byAdeel Ahmed
- The Impact of Contact on Stigmatizing Attitudes Toward People With Mental IllnessUploaded bydavidmdlr
- Development of Ergonomics FurnitureUploaded byqin_syiqin
- 05 AccelerationDownIncline-2Uploaded byPeter
- Project Plan Part OneUploaded byCM
- MemUploaded byoloyede_wole3741
- SAS Advance-3-1Uploaded byPrem
- float sink lab 2Uploaded byapi-388627256
- A Framework for Software Quality Assurance Using Agile MethodologyUploaded byIJSTR Research Publication
- Training Mannual on M&EUploaded byapi-3733074
- LACIP Background PaperUploaded byhamadgondal
- Evaluating Software Architectures Methods and Case Studies PDF DownloadUploaded byPatti
- LR04Uploaded byrajendra12singh
- A2-QMTUploaded byZeeshan Ali
- ABET-Choosing_Assessment_Methods.pdfUploaded bymmsoledad
- CT3_Sol_0510Uploaded byNathan Rk
- Risk Management2Uploaded byAslam Pervaiz
- 243426008-ITP-Mini-Pile.pdfUploaded byscriptd_ozd3n
- Research Methods PresentationUploaded byMukul Uddin
- Estimasi akumulasi karbon organik tanah.pdfUploaded byKurniawan Oween Sullivan
- PRONETT: SUPPORTING THE INTEGRATION OFUploaded byKoenraad
- Design of Machine Elements SyllabusUploaded byGirish Hanumaiah
- CS70 - Lecture 24Uploaded byAman Sufi
- 8-Hypothesis 28 Oct 11Uploaded byPriyanka_Bagdi_1938