0% found this document useful (0 votes)
52 views1 page

Dfz-Visit (V) : Source and The Search Is Repeated From That Source. This Entire Process Is Repeated Unnl An

Depth First Search (DFS) explores edges from the most recently discovered vertex and backtracks when all edges are explored, continuing until all reachable vertices are discovered. Each vertex is assigned discovery and finishing timestamps, and the algorithm uses a predecessor field to track the search path. The overall time complexity of DFS is O(V), where V is the number of vertices in the graph.

Uploaded by

Shahla Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views1 page

Dfz-Visit (V) : Source and The Search Is Repeated From That Source. This Entire Process Is Repeated Unnl An

Depth First Search (DFS) explores edges from the most recently discovered vertex and backtracks when all edges are explored, continuing until all reachable vertices are discovered. Each vertex is assigned discovery and finishing timestamps, and the algorithm uses a predecessor field to track the search path. The overall time complexity of DFS is O(V), where V is the number of vertices in the graph.

Uploaded by

Shahla Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ELEMENTARY GRAPHS ALGORITHMS 409

26.4DEPTH FIRST SEARCH


In depth-tirst search, edges are explored out of the most recently
discovered vertex v that
the search
still has unexplored edges leaving it. When all of Us edges have beern explored,This
backtracks to explore edges leaving the vertex from which v was discovered. process
Continues until we have discovered all the vertices that are reachable frorn the original
a new
SOurce vertex. If any undiscovered vertices remain, then one of them is selected as
source and the search is repeated from that source. Thisentire process is repeated unnl an
vertices are discovered.
As in the BFS, whenever a vertex v is discovered during ascan of the adjacency list of an
already discovered vertex , DES records this by setting ¯s predecessor field n[v] to u In DFS
predecessor subgraph is composed of several trees, because the search may be repeated
from multiple sources.
In DFS, each vertex vhas two timestamnps: the first timestamp d[v]ie. discovery time records
when v is first discovered ie. grayed, and the second timestamp f[v] i.e. finishing time
records when the search finishes exarnining v's adjacency list i.e. blacked. For every vertex
d[ul< f[u
DFS(G)
1. for each vertex u e V[G]
2. do color[u] WHITE
3. n[u] NIL
4. time 0
5. for each vertex u e V[G]
6. do if color[u] = WHITE
7. then DFS-VISIT(U)
DFS-VISIT(u)
1. color[u] - GRAY º White vertex u has just been discovered.
2. time -time +1
3. d[u]<-time
4. for eachve Adju]) D Explore edge (u, v)
5. o if color[v] = WHITE
6. then [v]+u
DFZ-VISIT (V) D Blacken u, it is finished.
8. colorlu] BLACK,
9. fluj+ timè time +1
Analysis
In this we use aggregate analysis. The loops on lines 1-3 and lines 5-7 of DFS take time 0(V)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy