SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
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….

Contenu connexe

Tendances

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
 

Tendances (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
 

Similaire à 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
 

Plus de 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
 

Dernier

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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