SlideShare a Scribd company logo
1 of 31
GRAPH
PRESENTED BY
R.RAMADEVI
M.sc(CS & IT)
NADAR SARASWATHI COLLEGE OF ARTS & SCIENCE
THENI
GRAPH TRAVERSALS
 • Depth-First Search
 • Breadth-First Search
Depth-first search (DFS)
• A depth-first search (DFS) in an undirected graph G is like
wandering in a labyrinth with a string and a can of red paint without
getting lost.
• We start at vertex s, tying the end of our string to the point and
paintings “visited”. Next we label s as our current vertex called u.
• Now we travel along an arbitrary edge (u,v)
.If edge (u,v) leads us to an already visited vertex v we return to u.
Depth-first search (DFS)
1. If vertex v is unvisited, we unroll our string and move to v, paint v
“visited”, set v as our current vertex, and repeat the previous steps.
2.Eventually, we will get to a point where all incident edges on u lead
to visited vertices.
3.We then backtrack by unrolling our string to a previously visited
vertex v.
4.Then v becomes our current vertex and we repeat the previous steps
Depth-First Search
 Algorithm DFS(v);
 Input: A vertex v in a graph
 Output: A labeling of the edges as “discovery” edges
and “backedges”
for each edge e incident on v do
if edge e is unexplored then
let w be the other endpoint of e
if vertex w is unexplored then
label e as a discovery edge
recursively call DFS(w)
else
label e as a backedge
Depth First Search
Depth First Search
Generic Depth First Search
public abstract class DFS {
protected Object dfsVisit(Vertex v) {
protected InspectableGraph graph;
protected Object visitResult;
initResult();
startVisit(v);
mark(v);
for (Enumeration inEdges = graph.incidentEdges(v);
inEdges.hasMoreElements();) {
Edge nextEdge = (Edge) inEdges.nextElement();
if (!isMarked(nextEdge)) { // found an unexplored edge
mark(nextEdge);
Vertex w = graph.opposite(v, nextEdge);
if (!isMarked(w)) { // discovery edge
mark(nextEdge);
traverseDiscovery(nextEdge, v);
if (!isDone())
VisitResult = dfVisit(w); }
else // back edge
TraverseBack(nextEdge, v);
}
}
FinishVisit(v);
return result();
}
Breadth-First Search
 Like DFS, a Breadth-First Search (BFS) traverses a connected
component of a graph, and in doing so defines a spanning tree with
several useful properties
 The starting vertex s has level 0, and, as in DFS , defines that point as
an “anchor.”
 In the first round, the string is unrolled the length of one edge, and all of
the edges that are only one edge away from the anchor are visited.
 These edges are placed into level 1
Breadth-First Search
 In the second round, all the new edges that can be reached by
unrolling the string 2 edges are visited and placed in level 2.
 This continues until every vertex has been assigned a level.
 The label of any vertex v corresponds to the length of the shortest
path from s to v.
BFS - A Graphical Representation
More BFS
BFS Pseudo-Code
Algorithm BFS(s):
Input: A vertex s in a graph
Output: A labeling of the edges as “discovery” edges
and “cross edges”
initialize container L0 to contain vertex s
i ¬ 0
while Li is not empty do
create container Li+1 to initially be empty
for each vertex v in Li do
if edge e incident on v do
let w be the other endpoint of e
if vertex w is unexplored then
label e as a discovery edge
insert w into Li+1
else
label e as a cross edge
i ¬ i + 1
Spanning tree
A spanning tree of a graph is just a subgraph that contains all the vertices and is a
tree.
A graph may have many spanning trees.
Minimum Spanning Trees
 The Minimum Spanning Tree for a given graph is the Spanning Tree
of minimum cost for that graph.
Algorithms for Obtaining the Minimum
Spanning Tree
 Kruskal's Algorithm
 Prim's Algorithm
 Boruvka's Algorithm
Kruskal's Algorithm
 This algorithm creates a forest of trees. Initially the forest consists of n single
node trees (and no edges).
 At each step, we add one edge (the cheapest one) so that it joins two trees
together.
 If it were to form a cycle, it would simply link two nodes that were already part of
a single connected tree, so that this edge would not be needed.
Complete graph
Prim's Algorithm
 This algorithm starts with one node.
 It then, one by one, adds a node that is unconnected to the new
graph to the new graph, each time selecting the node.
 whose connecting edge has the smallest weight out of the available
nodes’ connecting edges.
Boruvka's Algorithm
 This algorithm is similar to Prim’s, but nodes are added to the new
graph in parallel all around the graph.
 It creates a list of trees, each containing one node from the original
graph and proceeds to merge them along the smallest-weight
connecting edges until there’s only one tree, which is, of course, the
MST.
 It works rather like a merge sort.
THANKYOU!!!!!

More Related Content

What's hot

Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
2.1 graph basic
2.1 graph basic 2.1 graph basic
2.1 graph basic Krish_ver2
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structuresSavit Chandra
 
Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data StructureGaurang Dobariya
 
Data Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneData Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneDoug Needham
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c languageSARITHA REDDY
 
Data Structure : Graph and Graph Traversing
Data Structure : Graph and Graph TraversingData Structure : Graph and Graph Traversing
Data Structure : Graph and Graph TraversingVikas Chandwani
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsYi-Lung Tsai
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graphRounak Biswas
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsAshikur Rahman
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7Bianca Teşilă
 

What's hot (20)

Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
2.1 graph basic
2.1 graph basic 2.1 graph basic
2.1 graph basic
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
Graphss
GraphssGraphss
Graphss
 
Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
 
Data Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneData Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZone
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Data Structure : Graph and Graph Traversing
Data Structure : Graph and Graph TraversingData Structure : Graph and Graph Traversing
Data Structure : Graph and Graph Traversing
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
Graph
GraphGraph
Graph
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphs
 
Data structures and algorithms lab7
Data structures and algorithms lab7Data structures and algorithms lab7
Data structures and algorithms lab7
 

Similar to Graphs in Data Structure

Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfChristianKapsales1
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchzukun
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx pptDhruvilSTATUS
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
Social network analysis
Social network analysisSocial network analysis
Social network analysisStefanie Zhao
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxRajitha Reddy Alugati
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxsahilpawar2426
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdfamitbhachne
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Mohanlal Sukhadia University (MLSU)
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)Akshay soni
 

Similar to Graphs in Data Structure (20)

Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Graphs
GraphsGraphs
Graphs
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Skiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first searchSkiena algorithm 2007 lecture11 breadth deapth first search
Skiena algorithm 2007 lecture11 breadth deapth first search
 
U1 L5 DAA.pdf
U1 L5 DAA.pdfU1 L5 DAA.pdf
U1 L5 DAA.pdf
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
Social network analysis
Social network analysisSocial network analysis
Social network analysis
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
 
Data structure note
Data structure noteData structure note
Data structure note
 
Bfs dfs
Bfs dfsBfs dfs
Bfs dfs
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
Weighted graphs
Weighted graphsWeighted graphs
Weighted graphs
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Graphs
GraphsGraphs
Graphs
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 

More from lalithambiga kamaraj (20)

Firewall in Network Security
Firewall in Network SecurityFirewall in Network Security
Firewall in Network Security
 
Data Compression in Multimedia
Data Compression in MultimediaData Compression in Multimedia
Data Compression in Multimedia
 
Data CompressionMultimedia
Data CompressionMultimediaData CompressionMultimedia
Data CompressionMultimedia
 
Digital Audio in Multimedia
Digital Audio in MultimediaDigital Audio in Multimedia
Digital Audio in Multimedia
 
Network Security: Physical security
Network Security: Physical security Network Security: Physical security
Network Security: Physical security
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Data structure
Data structureData structure
Data structure
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Digital Image Processing
Digital Image ProcessingDigital Image Processing
Digital Image Processing
 
Estimating Software Maintenance Costs
Estimating Software Maintenance CostsEstimating Software Maintenance Costs
Estimating Software Maintenance Costs
 
Datamining
DataminingDatamining
Datamining
 
Digital Components
Digital ComponentsDigital Components
Digital Components
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Io management disk scheduling algorithm
Io management disk scheduling algorithmIo management disk scheduling algorithm
Io management disk scheduling algorithm
 
Recovery system
Recovery systemRecovery system
Recovery system
 
File management
File managementFile management
File management
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Inheritance
InheritanceInheritance
Inheritance
 
Managing console of I/o operations & working with files
Managing console of I/o operations & working with filesManaging console of I/o operations & working with files
Managing console of I/o operations & working with files
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

Graphs in Data Structure

  • 1. GRAPH PRESENTED BY R.RAMADEVI M.sc(CS & IT) NADAR SARASWATHI COLLEGE OF ARTS & SCIENCE THENI
  • 2. GRAPH TRAVERSALS  • Depth-First Search  • Breadth-First Search
  • 3. Depth-first search (DFS) • A depth-first search (DFS) in an undirected graph G is like wandering in a labyrinth with a string and a can of red paint without getting lost. • We start at vertex s, tying the end of our string to the point and paintings “visited”. Next we label s as our current vertex called u. • Now we travel along an arbitrary edge (u,v) .If edge (u,v) leads us to an already visited vertex v we return to u.
  • 4. Depth-first search (DFS) 1. If vertex v is unvisited, we unroll our string and move to v, paint v “visited”, set v as our current vertex, and repeat the previous steps. 2.Eventually, we will get to a point where all incident edges on u lead to visited vertices. 3.We then backtrack by unrolling our string to a previously visited vertex v. 4.Then v becomes our current vertex and we repeat the previous steps
  • 5. Depth-First Search  Algorithm DFS(v);  Input: A vertex v in a graph  Output: A labeling of the edges as “discovery” edges and “backedges” for each edge e incident on v do if edge e is unexplored then let w be the other endpoint of e if vertex w is unexplored then label e as a discovery edge recursively call DFS(w) else label e as a backedge
  • 8. Generic Depth First Search public abstract class DFS { protected Object dfsVisit(Vertex v) { protected InspectableGraph graph; protected Object visitResult; initResult(); startVisit(v); mark(v); for (Enumeration inEdges = graph.incidentEdges(v); inEdges.hasMoreElements();) { Edge nextEdge = (Edge) inEdges.nextElement(); if (!isMarked(nextEdge)) { // found an unexplored edge
  • 9. mark(nextEdge); Vertex w = graph.opposite(v, nextEdge); if (!isMarked(w)) { // discovery edge mark(nextEdge); traverseDiscovery(nextEdge, v); if (!isDone()) VisitResult = dfVisit(w); } else // back edge TraverseBack(nextEdge, v); } } FinishVisit(v); return result(); }
  • 10. Breadth-First Search  Like DFS, a Breadth-First Search (BFS) traverses a connected component of a graph, and in doing so defines a spanning tree with several useful properties  The starting vertex s has level 0, and, as in DFS , defines that point as an “anchor.”  In the first round, the string is unrolled the length of one edge, and all of the edges that are only one edge away from the anchor are visited.  These edges are placed into level 1
  • 11. Breadth-First Search  In the second round, all the new edges that can be reached by unrolling the string 2 edges are visited and placed in level 2.  This continues until every vertex has been assigned a level.  The label of any vertex v corresponds to the length of the shortest path from s to v.
  • 12. BFS - A Graphical Representation
  • 14. BFS Pseudo-Code Algorithm BFS(s): Input: A vertex s in a graph Output: A labeling of the edges as “discovery” edges and “cross edges” initialize container L0 to contain vertex s i ¬ 0 while Li is not empty do create container Li+1 to initially be empty for each vertex v in Li do if edge e incident on v do let w be the other endpoint of e if vertex w is unexplored then label e as a discovery edge insert w into Li+1 else label e as a cross edge i ¬ i + 1
  • 15. Spanning tree A spanning tree of a graph is just a subgraph that contains all the vertices and is a tree. A graph may have many spanning trees.
  • 16.
  • 17. Minimum Spanning Trees  The Minimum Spanning Tree for a given graph is the Spanning Tree of minimum cost for that graph.
  • 18. Algorithms for Obtaining the Minimum Spanning Tree  Kruskal's Algorithm  Prim's Algorithm  Boruvka's Algorithm
  • 19. Kruskal's Algorithm  This algorithm creates a forest of trees. Initially the forest consists of n single node trees (and no edges).  At each step, we add one edge (the cheapest one) so that it joins two trees together.  If it were to form a cycle, it would simply link two nodes that were already part of a single connected tree, so that this edge would not be needed.
  • 20.
  • 22. Prim's Algorithm  This algorithm starts with one node.  It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time selecting the node.  whose connecting edge has the smallest weight out of the available nodes’ connecting edges.
  • 23.
  • 24.
  • 25. Boruvka's Algorithm  This algorithm is similar to Prim’s, but nodes are added to the new graph in parallel all around the graph.  It creates a list of trees, each containing one node from the original graph and proceeds to merge them along the smallest-weight connecting edges until there’s only one tree, which is, of course, the MST.  It works rather like a merge sort.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.