SlideShare a Scribd company logo
1 of 20
Download to read offline
GraphRepresentations
RAMKRISHNA
BHAGAT
Contents
●
●
●
Introduction
Applications
Representations
➢ Sequential
➢ Linked
● TraversalAlgorithms
Introduction
A graph can be defined as group of vertices and edges that are used to connect these vertices. A graph can be seen as a cyclic
tree, where the vertices (Nodes) maintain any complex relationship among them instead of having parent child relationship.
Applications of Graph
Representations of graph
❖ Sequential Representation
❖ Linked Representation
Sequential Representation
In sequential representation, we use adjacency matrix to store the mapping represented by vertices and edges. In adjacency
matrix, the rows and columns are represented by the graph vertices. A graph having n vertices, will have a dimension n x n.
Linked Representation
In the linked representation, an adjacency list is used to store the Graph into the computer's memory.
Graph Traversal Algorithm
● Breadth First Search
● Depth First Search
Breadth First Search (BFS) Algorithm
Breadth first search is a graph traversal algorithm that starts traversing the graph from root node and explores all the
neighbouring nodes. Then, it selects the nearest node and explore all the unexplored nodes. The algorithm follows the same
process for each of the nearest node until it finds the goal.
Steps :
1. AddAtoQUEUE1andNULLtoQUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
2.DeletetheNodeAfromQUEUE1andinsert all its neighbours.
InsertNodeAinto QUEUE2
QUEUE1 = {A}
QUEUE2 = {NULL}
3.DeletethenodeBfromQUEUE1andinsertall its neighbours.
InsertnodeBinto QUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
:4.DeletethenodeDfromQUEUE1andinsertall its neighbours.
SinceFis theonlyneighbourofit whichhasbeen inserted,
wewill notinsertit again.InsertnodeDintoQUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
5.DeletethenodeCfromQUEUE1andinsertall its neighbours.
AddnodeCtoQUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
6.RemoveFfromQUEUE1andaddall its neighbours.Sinceall ofits neighbours
hasalready beenadded,wewill notaddthemagain.AddnodeFtoQUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
7. RemoveEfromQUEUE1,all ofE'sneighbourshasalready beenadded to
QUEUE1thereforewewill notaddthemagain.Allthenodesarevisited
andthetarget nodei.e.Eis encounteredintoQUEUE2.
QUEUE1 = {A}
QUEUE2 = {NULL}
Now, backtrack from E to A, using the nodes available in QUEUE2.
The minimum path will be A → B → C → E.
Depth First Search (BFS) Algorithm
Depth first search (DFS) algorithm starts with the initial node of the graph G, and then goes to deeper and deeper until we find
the goal node or the node which has no children. The algorithm, then backtracks from the dead end towards the most recent node
that is yet to be completely unexplored.
Steps :
1. PushHontothe Stack.
QUEUE1 = {A}
QUEUE2 = {NULL}
2.POPthetopelementofthestack i.e. H,printit andpushall the
neighboursofHontothestack that areis ready state.
QUEUE1 = {A}
QUEUE2 = {NULL}
3.Popthetopelementofthestack i.e.A,printit andpushall the
neighboursofAontothestack thatareinready state
QUEUE1 = {A}
QUEUE2 = {NULL}
:4.Popthetopelementofthestack i.e.D,printit andpushall theneighbours
ofDontothestack that areinready state.
QUEUE1 = {A}
QUEUE2 = {NULL}
5.Popthetopelementofthestack i.e.F,printit andpushall theneighbours
ofFontothestack that areinready state.
QUEUE1 = {A}
QUEUE2 = {NULL}
6.Pop the top of the stack i.e.Band pushall the neighbours
QUEUE1 = {A}
QUEUE2 = {NULL}
:
7. Popthetopofthestack i.e.Candpushall theneighbours.
QUEUE1 = {A}
QUEUE2 = {NULL}
8.Popthetopofthestack i.e.Gandpushall its neighbours.
QUEUE1 = {A}
QUEUE2 = {NULL}
9.Pop the top of the stack i.e.Eand pushall its neighbours.
QUEUE1 = {A}
QUEUE2 = {NULL}
Hence, the stack now becomes empty and all the nodes of the graph have been traversed.
The printing sequence of the graph will be :
H → A → D → F → B → C → G → E
Thank You….

More Related Content

What's hot

Ch 1 review stations (Classwork)
Ch 1 review stations (Classwork)Ch 1 review stations (Classwork)
Ch 1 review stations (Classwork)leblance
 
Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Anshul gour
 
13 unsupervised learning clustering
13 unsupervised learning   clustering13 unsupervised learning   clustering
13 unsupervised learning clusteringTanmayVijay1
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
 
Parameters of t SNE
Parameters of t SNEParameters of t SNE
Parameters of t SNEAli Madani
 
U6 Cn2 Definite Integrals Intro
U6 Cn2 Definite Integrals IntroU6 Cn2 Definite Integrals Intro
U6 Cn2 Definite Integrals IntroAlexander Burt
 
Transformations
TransformationsTransformations
Transformationsestelav
 
14 dimentionality reduction
14 dimentionality reduction14 dimentionality reduction
14 dimentionality reductionTanmayVijay1
 
Boolean Algebra by SUKHDEEP SINGH
Boolean Algebra by SUKHDEEP SINGHBoolean Algebra by SUKHDEEP SINGH
Boolean Algebra by SUKHDEEP SINGHSukhdeep Bisht
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithmfaisal2204
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraguest1f4fb3
 
12 support vector machines
12 support vector machines12 support vector machines
12 support vector machinesTanmayVijay1
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning treeAlona Salva
 

What's hot (20)

Ch 1 review stations (Classwork)
Ch 1 review stations (Classwork)Ch 1 review stations (Classwork)
Ch 1 review stations (Classwork)
 
Reading2018 kikuta
Reading2018 kikutaReading2018 kikuta
Reading2018 kikuta
 
Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)Dijkstra & flooding ppt(Routing algorithm)
Dijkstra & flooding ppt(Routing algorithm)
 
13 unsupervised learning clustering
13 unsupervised learning   clustering13 unsupervised learning   clustering
13 unsupervised learning clustering
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
 
Parameters of t SNE
Parameters of t SNEParameters of t SNE
Parameters of t SNE
 
U6 Cn2 Definite Integrals Intro
U6 Cn2 Definite Integrals IntroU6 Cn2 Definite Integrals Intro
U6 Cn2 Definite Integrals Intro
 
Transformations
TransformationsTransformations
Transformations
 
14 dimentionality reduction
14 dimentionality reduction14 dimentionality reduction
14 dimentionality reduction
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Boolean Algebra by SUKHDEEP SINGH
Boolean Algebra by SUKHDEEP SINGHBoolean Algebra by SUKHDEEP SINGH
Boolean Algebra by SUKHDEEP SINGH
 
Module#8 notes
Module#8 notesModule#8 notes
Module#8 notes
 
QMC: Operator Splitting Workshop, Behavior of BFGS on Nonsmooth Convex Functi...
QMC: Operator Splitting Workshop, Behavior of BFGS on Nonsmooth Convex Functi...QMC: Operator Splitting Workshop, Behavior of BFGS on Nonsmooth Convex Functi...
QMC: Operator Splitting Workshop, Behavior of BFGS on Nonsmooth Convex Functi...
 
Dijkstra’s algorithm
Dijkstra’s algorithmDijkstra’s algorithm
Dijkstra’s algorithm
 
KRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitraKRUSKAL'S algorithm from chaitra
KRUSKAL'S algorithm from chaitra
 
12 support vector machines
12 support vector machines12 support vector machines
12 support vector machines
 
My presentation minimum spanning tree
My presentation minimum spanning treeMy presentation minimum spanning tree
My presentation minimum spanning tree
 
Minimum spanning tree
Minimum spanning treeMinimum spanning tree
Minimum spanning tree
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Implementation
ImplementationImplementation
Implementation
 

Similar to Graph Representation (20)

Graphs
GraphsGraphs
Graphs
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
Graphs
GraphsGraphs
Graphs
 
Graphs
GraphsGraphs
Graphs
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
Spectral graph theory
Spectral graph theorySpectral graph theory
Spectral graph theory
 
breadth first search
breadth first searchbreadth first search
breadth first search
 
26 spanning
26 spanning26 spanning
26 spanning
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Data structure note
Data structure noteData structure note
Data structure note
 
Graph in data structures
Graph in data structuresGraph in data structures
Graph in data structures
 
Analysis & design of algorithm
Analysis & design of algorithmAnalysis & design of algorithm
Analysis & design of algorithm
 

More from Ramkrishna bhagat (7)

JAVA APPLETS
JAVA APPLETSJAVA APPLETS
JAVA APPLETS
 
Binary search
Binary search Binary search
Binary search
 
DBTG MODEL
DBTG MODELDBTG MODEL
DBTG MODEL
 
IPV6 , ipv6 ,TCP/IP, TCP ,IP
IPV6 , ipv6 ,TCP/IP, TCP ,IPIPV6 , ipv6 ,TCP/IP, TCP ,IP
IPV6 , ipv6 ,TCP/IP, TCP ,IP
 
Data warehouse
Data warehouseData warehouse
Data warehouse
 
22 ramkrishna
22 ramkrishna22 ramkrishna
22 ramkrishna
 
E-Ball Technology
E-Ball TechnologyE-Ball Technology
E-Ball Technology
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 

Graph Representation

  • 3. Introduction A graph can be defined as group of vertices and edges that are used to connect these vertices. A graph can be seen as a cyclic tree, where the vertices (Nodes) maintain any complex relationship among them instead of having parent child relationship.
  • 5. Representations of graph ❖ Sequential Representation ❖ Linked Representation
  • 6. Sequential Representation In sequential representation, we use adjacency matrix to store the mapping represented by vertices and edges. In adjacency matrix, the rows and columns are represented by the graph vertices. A graph having n vertices, will have a dimension n x n.
  • 7.
  • 8. Linked Representation In the linked representation, an adjacency list is used to store the Graph into the computer's memory.
  • 9.
  • 10. Graph Traversal Algorithm ● Breadth First Search ● Depth First Search
  • 11. Breadth First Search (BFS) Algorithm Breadth first search is a graph traversal algorithm that starts traversing the graph from root node and explores all the neighbouring nodes. Then, it selects the nearest node and explore all the unexplored nodes. The algorithm follows the same process for each of the nearest node until it finds the goal.
  • 12. Steps : 1. AddAtoQUEUE1andNULLtoQUEUE2. QUEUE1 = {A} QUEUE2 = {NULL} 2.DeletetheNodeAfromQUEUE1andinsert all its neighbours. InsertNodeAinto QUEUE2 QUEUE1 = {A} QUEUE2 = {NULL} 3.DeletethenodeBfromQUEUE1andinsertall its neighbours. InsertnodeBinto QUEUE2. QUEUE1 = {A} QUEUE2 = {NULL}
  • 13. :4.DeletethenodeDfromQUEUE1andinsertall its neighbours. SinceFis theonlyneighbourofit whichhasbeen inserted, wewill notinsertit again.InsertnodeDintoQUEUE2. QUEUE1 = {A} QUEUE2 = {NULL} 5.DeletethenodeCfromQUEUE1andinsertall its neighbours. AddnodeCtoQUEUE2. QUEUE1 = {A} QUEUE2 = {NULL} 6.RemoveFfromQUEUE1andaddall its neighbours.Sinceall ofits neighbours hasalready beenadded,wewill notaddthemagain.AddnodeFtoQUEUE2. QUEUE1 = {A} QUEUE2 = {NULL}
  • 14. 7. RemoveEfromQUEUE1,all ofE'sneighbourshasalready beenadded to QUEUE1thereforewewill notaddthemagain.Allthenodesarevisited andthetarget nodei.e.Eis encounteredintoQUEUE2. QUEUE1 = {A} QUEUE2 = {NULL} Now, backtrack from E to A, using the nodes available in QUEUE2. The minimum path will be A → B → C → E.
  • 15. Depth First Search (BFS) Algorithm Depth first search (DFS) algorithm starts with the initial node of the graph G, and then goes to deeper and deeper until we find the goal node or the node which has no children. The algorithm, then backtracks from the dead end towards the most recent node that is yet to be completely unexplored.
  • 16. Steps : 1. PushHontothe Stack. QUEUE1 = {A} QUEUE2 = {NULL} 2.POPthetopelementofthestack i.e. H,printit andpushall the neighboursofHontothestack that areis ready state. QUEUE1 = {A} QUEUE2 = {NULL} 3.Popthetopelementofthestack i.e.A,printit andpushall the neighboursofAontothestack thatareinready state QUEUE1 = {A} QUEUE2 = {NULL}
  • 17. :4.Popthetopelementofthestack i.e.D,printit andpushall theneighbours ofDontothestack that areinready state. QUEUE1 = {A} QUEUE2 = {NULL} 5.Popthetopelementofthestack i.e.F,printit andpushall theneighbours ofFontothestack that areinready state. QUEUE1 = {A} QUEUE2 = {NULL} 6.Pop the top of the stack i.e.Band pushall the neighbours QUEUE1 = {A} QUEUE2 = {NULL}
  • 18. : 7. Popthetopofthestack i.e.Candpushall theneighbours. QUEUE1 = {A} QUEUE2 = {NULL} 8.Popthetopofthestack i.e.Gandpushall its neighbours. QUEUE1 = {A} QUEUE2 = {NULL} 9.Pop the top of the stack i.e.Eand pushall its neighbours. QUEUE1 = {A} QUEUE2 = {NULL}
  • 19. Hence, the stack now becomes empty and all the nodes of the graph have been traversed. The printing sequence of the graph will be : H → A → D → F → B → C → G → E