際際滷

際際滷Share a Scribd company logo
PRESENTED BY
D.ANANDHASILAMBARASAN
KIT - CBE
GRAPH TRAVERSALS IN DATA STRUCTURE
GRAPH TRAVERSALS
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 edges to be used in the search process without creating
loops that means using graph traversal we visit all vertices of graph without getting
into looping path.
There are two graph traversal techniques and they are as follows...
 BFS (breadth first search)
 DFS (depth first search)
BFS (Breadth First Search)
 BFS traversal of a graph, produces a spanning tree as final result.
 Spanning tree is a graph without any loops.
 We use queue data structure with maximum size of total number of vertices in the
graph to implement BFS traversal of a graph.
We use the following steps to implement BFS traversal.
Step 1: Define a queue of size total number of vertices in the graph.
Step 2: Select any vertex as starting point for traversal. Visit that vertex and insert it
into the queue.
Step 3: Visit all the adjacent vertices of the vertex which is at front of the queue which is
not visited and insert them into the queue.
Step 4: When there is no new vertex to be visit from the vertex at front of the queue then
delete that vertex from the queue.
Step 5: Repeat step 3 and 4 until queue becomes empty.
Step 6: When queue becomes empty, then produce final spanning tree by removing
unused edges from the graph.
Graph traversals in Data Structures
Graph traversals in Data Structures
DFS (DEPTH FIRST SEARCH)
DFS traversal of a graph, produces a spanning tree as final result. Spanning tree is a
graph without any loops.
We use stack data structure with 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 as starting point for traversal. Visit that vertex and push it on to
the stack.
Step 3: visit any one of the adjacent vertex of the vertex 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 use back tracking and 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 tracking is coming back to the vertex from which we came to current vertex.
Graph traversals in Data Structures
Graph traversals in Data Structures
Graph traversals in Data Structures

More Related Content

What's hot (20)

Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
Spanning trees
Spanning treesSpanning trees
Spanning trees
Shareb Ismaeel
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
satya parsana
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
Arafat Hossan
sorting and its types
sorting and its typessorting and its types
sorting and its types
SIVASHANKARIRAJAN
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
Sorting
SortingSorting
Sorting
Ashim Lamichhane
Hashing
HashingHashing
Hashing
Amar Jukuntla
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
Anuj Modi
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h
Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
Arafat Hossan
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
Anuj Modi
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick

Similar to Graph traversals in Data Structures (20)

graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdf
SeethaDinesh
DFS_New.pptx
DFS_New.pptxDFS_New.pptx
DFS_New.pptx
sandeep54552
Bfs new
Bfs newBfs new
Bfs new
sandeep54552
Bfs new
Bfs newBfs new
Bfs new
sandeep54552
bfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptxbfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptx
saurabhpandey679381
Problem Solving through Search - Uninformed Search
Problem Solving through Search - Uninformed SearchProblem Solving through Search - Uninformed Search
Problem Solving through Search - Uninformed Search
DuraiRaj315751
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
amitbhachne
Unit VI - Graphs.ppt
Unit VI - Graphs.pptUnit VI - Graphs.ppt
Unit VI - Graphs.ppt
HODElex
Data structure note
Data structure noteData structure note
Data structure note
Muhammad Nawaz
Bfs and dfs
Bfs and dfsBfs and dfs
Bfs and dfs
utsav patel
Graphs
GraphsGraphs
Graphs
KomalPaliwal3
Ai1.pdf
Ai1.pdfAi1.pdf
Ai1.pdf
kaxeca4096
Breadth First Search with example and solutions
Breadth First Search with example and solutionsBreadth First Search with example and solutions
Breadth First Search with example and solutions
Dr. Anand Bihari
Lecture # 02-Search Algorithms11111.pptx
Lecture # 02-Search Algorithms11111.pptxLecture # 02-Search Algorithms11111.pptx
Lecture # 02-Search Algorithms11111.pptx
TheSmartSolverAcadem
Search Algorithms in AI.pptx
Search Algorithms in AI.pptxSearch Algorithms in AI.pptx
Search Algorithms in AI.pptx
Dr.Shweta
bfs and dfs (data structures).pptx
bfs and dfs (data structures).pptxbfs and dfs (data structures).pptx
bfs and dfs (data structures).pptx
ssuser55cbdb
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
ShasidharaniD
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptx
ionutionescuionut
Data structure
Data structureData structure
Data structure
lalithambiga kamaraj
graphtraversals.pdf
graphtraversals.pdfgraphtraversals.pdf
graphtraversals.pdf
SeethaDinesh
bfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptxbfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptx
saurabhpandey679381
Problem Solving through Search - Uninformed Search
Problem Solving through Search - Uninformed SearchProblem Solving through Search - Uninformed Search
Problem Solving through Search - Uninformed Search
DuraiRaj315751
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
amitbhachne
Unit VI - Graphs.ppt
Unit VI - Graphs.pptUnit VI - Graphs.ppt
Unit VI - Graphs.ppt
HODElex
Data structure note
Data structure noteData structure note
Data structure note
Muhammad Nawaz
Breadth First Search with example and solutions
Breadth First Search with example and solutionsBreadth First Search with example and solutions
Breadth First Search with example and solutions
Dr. Anand Bihari
Lecture # 02-Search Algorithms11111.pptx
Lecture # 02-Search Algorithms11111.pptxLecture # 02-Search Algorithms11111.pptx
Lecture # 02-Search Algorithms11111.pptx
TheSmartSolverAcadem
Search Algorithms in AI.pptx
Search Algorithms in AI.pptxSearch Algorithms in AI.pptx
Search Algorithms in AI.pptx
Dr.Shweta
bfs and dfs (data structures).pptx
bfs and dfs (data structures).pptxbfs and dfs (data structures).pptx
bfs and dfs (data structures).pptx
ssuser55cbdb
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
Shuvongkor Barman
LAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptxLAB7_FILS_DSA_graphs_datastructures.pptx
LAB7_FILS_DSA_graphs_datastructures.pptx
ionutionescuionut

Recently uploaded (20)

Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17
Celine George
technology in banking ppt FOR E-CONTENT -2.ppt
technology in banking ppt  FOR E-CONTENT -2.ppttechnology in banking ppt  FOR E-CONTENT -2.ppt
technology in banking ppt FOR E-CONTENT -2.ppt
HARIHARAN A
Antifungal drug are those medicine that kill or stop the growth of fungi.
Antifungal drug are those medicine that kill or stop the growth of fungi.Antifungal drug are those medicine that kill or stop the growth of fungi.
Antifungal drug are those medicine that kill or stop the growth of fungi.
AbuShahma9
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
Prabhakar Singh Patel
Introduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz KhanIntroduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz Khan
Systematic Reviews Network (SRN)
Conrad "Accessibility Essentials: Introductory Seminar"
Conrad "Accessibility Essentials: Introductory Seminar"Conrad "Accessibility Essentials: Introductory Seminar"
Conrad "Accessibility Essentials: Introductory Seminar"
National Information Standards Organization (NISO)
Developing Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Developing Topic and Research Question for Systematic Reviews - Emmanuel EkporDeveloping Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Developing Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Systematic Reviews Network (SRN)
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptxBIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
maniramkumar
McElaney "What is inclusive publishing and why do we care about accessibility...
McElaney "What is inclusive publishing and why do we care about accessibility...McElaney "What is inclusive publishing and why do we care about accessibility...
McElaney "What is inclusive publishing and why do we care about accessibility...
National Information Standards Organization (NISO)
NC Advisory Council on Student Safety and Well-Being
NC Advisory Council on Student Safety and Well-BeingNC Advisory Council on Student Safety and Well-Being
NC Advisory Council on Student Safety and Well-Being
Mebane Rash
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Sue Beckingham
"The Write Path: Navigating Research Writing, Publication, and Professional G...
"The Write Path: Navigating Research Writing, Publication, and Professional G..."The Write Path: Navigating Research Writing, Publication, and Professional G...
"The Write Path: Navigating Research Writing, Publication, and Professional G...
neelottama
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdfIB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
Dr. Mahtab Alam
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation FourthStrategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
keileyrazawi
Mixed_Sinhala_Dual_Male_Names (1).pdf...
Mixed_Sinhala_Dual_Male_Names (1).pdf...Mixed_Sinhala_Dual_Male_Names (1).pdf...
Mixed_Sinhala_Dual_Male_Names (1).pdf...
keshanf79
UNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptxUNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptx
HARIHARAN A
10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx
Vivek Bhattji
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VIAnti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Samruddhi Khonde
Test Bank Pharmacology 3rd Edition Brenner Stevens
Test Bank Pharmacology 3rd Edition Brenner  StevensTest Bank Pharmacology 3rd Edition Brenner  Stevens
Test Bank Pharmacology 3rd Edition Brenner Stevens
evakimworwa38
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-6-2025 ver 5.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-6-2025 ver 5.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-6-2025 ver 5.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-6-2025 ver 5.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17Analysis of Conf File Parameters in Odoo 17
Analysis of Conf File Parameters in Odoo 17
Celine George
technology in banking ppt FOR E-CONTENT -2.ppt
technology in banking ppt  FOR E-CONTENT -2.ppttechnology in banking ppt  FOR E-CONTENT -2.ppt
technology in banking ppt FOR E-CONTENT -2.ppt
HARIHARAN A
Antifungal drug are those medicine that kill or stop the growth of fungi.
Antifungal drug are those medicine that kill or stop the growth of fungi.Antifungal drug are those medicine that kill or stop the growth of fungi.
Antifungal drug are those medicine that kill or stop the growth of fungi.
AbuShahma9
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
URINE SPECIMEN COLLECTION AND HANDLING CLASS 1 FOR ALL PARAMEDICAL OR CLINICA...
Prabhakar Singh Patel
Developing Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Developing Topic and Research Question for Systematic Reviews - Emmanuel EkporDeveloping Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Developing Topic and Research Question for Systematic Reviews - Emmanuel Ekpor
Systematic Reviews Network (SRN)
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptxBIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
BIOPHARMACEUTICS AND PHARMACOKINETICS(BP604T) - Copy (3).pptx
maniramkumar
NC Advisory Council on Student Safety and Well-Being
NC Advisory Council on Student Safety and Well-BeingNC Advisory Council on Student Safety and Well-Being
NC Advisory Council on Student Safety and Well-Being
Mebane Rash
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...
Sue Beckingham
"The Write Path: Navigating Research Writing, Publication, and Professional G...
"The Write Path: Navigating Research Writing, Publication, and Professional G..."The Write Path: Navigating Research Writing, Publication, and Professional G...
"The Write Path: Navigating Research Writing, Publication, and Professional G...
neelottama
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdfIB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
IB-Unit-4 BBA BVIMR 2022 Syllabus_watermark.pdf
Dr. Mahtab Alam
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation FourthStrategic Corporate Social Responsibility: Sustainable Value Creation Fourth
Strategic Corporate Social Responsibility: Sustainable Value Creation Fourth
keileyrazawi
Mixed_Sinhala_Dual_Male_Names (1).pdf...
Mixed_Sinhala_Dual_Male_Names (1).pdf...Mixed_Sinhala_Dual_Male_Names (1).pdf...
Mixed_Sinhala_Dual_Male_Names (1).pdf...
keshanf79
UNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptxUNIT 1 Introduction to communication.pptx
UNIT 1 Introduction to communication.pptx
HARIHARAN A
10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx10.socialorganisationandsocialsystem .pptx
10.socialorganisationandsocialsystem .pptx
Vivek Bhattji
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VIAnti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Samruddhi Khonde
Test Bank Pharmacology 3rd Edition Brenner Stevens
Test Bank Pharmacology 3rd Edition Brenner  StevensTest Bank Pharmacology 3rd Edition Brenner  Stevens
Test Bank Pharmacology 3rd Edition Brenner Stevens
evakimworwa38

Graph traversals in Data Structures

  • 1. PRESENTED BY D.ANANDHASILAMBARASAN KIT - CBE GRAPH TRAVERSALS IN DATA STRUCTURE
  • 2. GRAPH TRAVERSALS 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 edges to be used in the search process without creating loops that means using graph traversal we visit all vertices of graph without getting into looping path. There are two graph traversal techniques and they are as follows... BFS (breadth first search) DFS (depth first search)
  • 3. BFS (Breadth First Search) BFS traversal of a graph, produces a spanning tree as final result. Spanning tree is a graph without any loops. We use queue data structure with maximum size of total number of vertices in the graph to implement BFS traversal of a graph. We use the following steps to implement BFS traversal. Step 1: Define a queue of size total number of vertices in the graph. Step 2: Select any vertex as starting point for traversal. Visit that vertex and insert it into the queue.
  • 4. Step 3: Visit all the adjacent vertices of the vertex which is at front of the queue which is not visited and insert them into the queue. Step 4: When there is no new vertex to be visit from the vertex at front of the queue then delete that vertex from the queue. Step 5: Repeat step 3 and 4 until queue becomes empty. Step 6: When queue becomes empty, then produce final spanning tree by removing unused edges from the graph.
  • 7. DFS (DEPTH FIRST SEARCH) DFS traversal of a graph, produces a spanning tree as final result. Spanning tree is a graph without any loops. We use stack data structure with 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 as starting point for traversal. Visit that vertex and push it on to the stack.
  • 8. Step 3: visit any one of the adjacent vertex of the vertex 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 use back tracking and 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 tracking is coming back to the vertex from which we came to current vertex.