Depth-First Search (DFS) Algorithm: Implementation and Running Time, Study notes of Computer Science

An in-depth look at the depth-first search (dfs) algorithm, including its implementation and running time analysis. Visualizations of dfs execution and stack usage, as well as explanations of the main steps in the algorithm and their time complexities.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-lj1-1
koofers-user-lj1-1 🇺🇸

9 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Implementing Depth-First
Search
Section 3.3
DFS Implementation
PDF created with pdfFactory trial version www.pdffactory.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Depth-First Search (DFS) Algorithm: Implementation and Running Time and more Study notes Computer Science in PDF only on Docsity!

Implementing Depth-First

Search

Section 3.

DFS Implementation

Explored nodes (shown in red) Stack

DFS Execution

Explored nodes (shown in red) Stack

Explored nodes (in red) Stack

DFS Execution

Explored nodes (in red) Stack

Explored nodes (in red) Stack

DFS Execution

Explored nodes (in red) Stack

Explored nodes (in red) Stack

DFS Execution

Explored nodes (in red) Stack

Explored nodes (in red) Stack

DFS Execution

Explored nodes (in red) Stack

Explored nodes (in red) Stack

DFS Execution

Explored nodes (in red) Stack

Explored nodes (in red) Stack

DFS Running Time p Running Time of DFS = O(m + n)

n Same as BFS

DFS Running Time p Main steps in the Algo.

n Adding and Deleting nodes to stack S

p Count node additions and deletions p Number of additions=Number of deletions

n Enough to count number of node additions

DFS Running Time p Main steps in the Algo.

n Adding and Deleting nodes to stack S

p Count node additions and deletions p Number of additions=Number of deletions

n Enough to count number of node additions

p Number of times node u gets added

= du (the degree of u)

DFS Running Time p Main steps in the Algo.

n Adding and Deleting nodes to stack S

p Count node additions and deletions p Number of additions=Number of deletions

n Enough to count number of node additions

p Number of times node u gets added

= du (the degree of u)

p Total Running time = O(Σu du) = O(m+n)