0% found this document useful (0 votes)
24 views4 pages

Graph Traversals - Data Structures

Graph traversal techniques are used to search vertices in a graph and determine the order to visit them. Depth-first search (DFS) uses a stack to visit adjacent unvisited vertices, going as deep as possible before backtracking. It produces a spanning tree. DFS involves pushing the starting vertex on a stack, visiting and pushing adjacent unvisited vertices, backtracking when no new vertices remain, and repeating until the stack is empty.
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)
24 views4 pages

Graph Traversals - Data Structures

Graph traversal techniques are used to search vertices in a graph and determine the order to visit them. Depth-first search (DFS) uses a stack to visit adjacent unvisited vertices, going as deep as possible before backtracking. It produces a spanning tree. DFS involves pushing the starting vertex on a stack, visiting and pushing adjacent unvisited vertices, backtracking when no new vertices remain, and repeating until the stack is empty.
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/ 4

11/1/2017 Graph Traversals :: Data Structures

Graph Traversals - DFS

Graph traversal is technique used for searching a vertex in a graph. The graph traversal is also used
to decide the order of vertices to be visit in the search process. A graph traversal finds the egdes to
be used in the search process without creating loops that means using graph traversal we visit all
verticces of graph without getting into looping path.

There are two graph traversal techniques and they are as follows...

1. DFS (Depth First Search)


2. BFS (Breadth First Search)

DFS (Depth First Search)

DFS traversal of a graph, produces aspanning treeas final result.Spanning Treeis a graph without
any loops. We useStack data structurewith maximum size of total number of vertices in the graph
to implement DFS traversal of a graph.

We use the following steps to implement DFS traversal...

Step 1:Define a Stack of size total number of vertices in the graph.


Step 2:Select any vertex asstarting pointfor traversal. Visit that vertex and push it on to the
Stack.
Step 3:Visit any one of theadjacentvertex of the verex which is at top of the stack which is not
visited and push it on to the stack.
Step 4: Repeat step 3 until there are no new vertex to be visit from the vertex on top of the
stack.
Step 5:When there is no new vertex to be visit then useback trackingand pop one vertex from
the stack.
Step 6:Repeat steps 3, 4 and 5 until stack becomes Empty.
Step 7:When stack becomes Empty, then produce final spanning tree by removing unused edges
from the graph

Back trackingis coming back to the vertex from which we came to current vertex.

Example

http://btechsmartclass.com/DS/U3_T10.html 1/4
11/1/2017 Graph Traversals :: Data Structures

http://btechsmartclass.com/DS/U3_T10.html 2/4
11/1/2017 Graph Traversals :: Data Structures

http://btechsmartclass.com/DS/U3_T10.html 3/4
11/1/2017 Graph Traversals :: Data Structures

http://btechsmartclass.com/DS/U3_T10.html 4/4

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