SlideShare a Scribd company logo
1 of 44
UNIVERSITY COLLEGE OF
SCIENCE
Submitted To :
Dr. Pooja Shrimali
Submitted By :
Komal Paliwal
& Jitendra Bhatia
GRAPH is non-linear data structure, it contains a
set of points known as Nodes(or Vertices) and set
of links known as Edges(or Arcs) which connect
the vertices. A graph is defined as follows....
“Graph is a collection of nodes and edges which
connects vertices in the graph.”
Generally, a graph G is represented as G=( V , E ),
where V is set of vertices and E is set of edges.
The following is a graph with 5 vertices and 6
edges.
This graph G can be defined as G =( V , E ).
Where V= {A,B,C,D,E}
and E={(A,B),(A,C),(A,D),(B,D),(C,D),(B,E),(E,D)}.
Edges
Vertices
A B
C D
E
We use the following term in data
structure...........
 Vertex
 Edges
a. Undirected graph
b. Directed graph
c. Weighted graph
 Undirected graph
 Directed graph
 Mixed graph
 End vertices or End points
 Origin
Description of these
terminology’s.
 Destination
 Adjacent
 Incident
 Outgoing Edge
 Incoming Edge
 Degree
 In Degree
 Out degree
 Parallel edges or Multiple
edges
 Self loop
 Simple graph
 Path
Graph data structure is represented
using following representations.....
1. Adjacency Matrix
2. Incidence Matrix
3. Adjacency List
In this representation, graph can be
represented using a matrix of size total
number of vertices by total number of
vertices. That means if a graph with 4 vertices
can be represents vertices. This matrix is
filled with either 1 or 0. here, 1 represents
there is an edge from row vertex to column
vertex and o represents there is no edge from
vertex to column vertex.
A B
E
C D
A
C
B
D
E
Undirected
graph
Directed
graph
A
B
C
D
E
A B C D E
0
1
1
1
0
1
0
0
1
1
1
0
0
1
0
1
1
1
1
1
0
1
0
1
0
A
B
C
D
E
A B C D E
0
0
0
1
0
1
0
0
0
0
1
0
0
0
0
0
1
1
1
0
0
1
0
1
0
For example :-
In this representation, graph can be
represented using a matrix of size total number
of vertices by total number of edges. That means
if a graph with 4 vertices and 6 edges can be
represented using a matrix of 4x6 class. In this
matrix, rows represents vertices and columns
represents edges. This matrix is filled with either
0 or 1 or -1. here, o represents row edge is not
connected to column vertex, 1 represents row
edge is connected as outgoing edge to column
vertex and -1 represents row edge is connected
as incoming edge to column vertex.
E1 E2 E3 E4 E5 E6 E7 E8
A
B
C
D
E
1
-1
0
0
0
1
0
-1
0
0
-1
0
0
1
0
0
1
0
-1
0
0
0
1
-1
0
0
0
0
1
-1
0
1
0
0
-1
0
0
0
1
0
A
DC
B
E
E1
E3
E7
E6
E4E2
E5
E8
For example :-
In this representation, every vertex of
graph contains list of its adjacent vertices.
For example :-This representation can also
be implemented using array as follows...
Reference Array
Adjacency Array
E
A B
C D
0
1
2
3
4
B C
D E
D
A D E
For example, consider the following directed graph representation
implemented using linked list....
E
BA
DC
A
B
C
D
E
E
E
D
B
D
D
A
C
Graph traversals 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 is also 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 traversal techniques and
they are as follows…
1. Depth First Traversal (D F S)
2. Breadth First Traversal (B F S)
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.
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 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
tracking and pop one vertex from the stack.
Step 6: Repeat steps 3,4and5 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.
Consider the following example graph to
perform DFS traversal :
DFS traversal on this example:
A B
DC
E
1. For an unweighted graph
2. Detecting cycle in a graph
3. Path finding
4. Topological sorting
5. Finding strongly connected component of a
graph
6. Solving puzzles with only one solution(such
as mazes).
 For an unweighted graph, DFS traversal of the
graph produces the minimum spanning tree and all
pair shortest path tree.
 Detecting cycle in a graph, A graph has cycle if and
if we see a back edge during DFS. So we can run
DFS for the graph and check for back edges.
 Path finding, We can specialize the DFS algorithm to
find a path between two given vertices u and z.
 Call DFS(G,u)with u as the start vertex.
 Use a stack S to keep track of the path between the
start vertex and the current vertex.
 As soon as destination vertex z is encountered,
return the path as the contents of the stack
DFS-iterative(G,s):
//Where G is graph and s is source vertex.
let S be stack
s.push(s)
marks s as visited
while(S is not empty);
//Pop a vertex from stack to visit next
v=S.top( )
S.pop( )
//Push all the neighbours of v in stack that
are not visited for all neighbors w of v in
Graph G:
if w is not visited :
s.push(w)
mark w as visited
The time complexity of DFS is O(V+E),
Where V is the number of nodes and
E is the number of edges.
Program of Depth First Traversal :
Breadth first search(BFS) algorithm traverses
a graph in a breadth ward motion and uses a
queue to remember to get the next vertex to
start a search, when a dead end occurs in any
iteration.
It employs the following rules :
Rule1 :Visit the adjacent vertex. Mark it as visited.
Display it. Insert it in a queue.
Rule2 :If no adjacent vertex is found , remove the
vertex from the queue.
Rule3 :Repeat Rule1 and Rule 2 till the queue is
empty.
Consider the following example graph to
perform BFS traversal :
BFS traversal on this example :
S
BA C
D
BFS(G,s) //where G is a graph and s is the source node
let Q be queue.
Q.enqueue(s) //Inserting s in queue until its neighbour
vertices are marked.
marks s as visited.
while(Q is not empty)
//Removing that vertex from queue,
whose neighbour will be visited now
v=Q.dequeue( )
//processing all the neighbours of v
for all neighbours w of v in Graph G
if w is not visited
Q.enqueue(w)
// Stores w in Q to further visit its neighbour
mark w as visited.
The time complexity of BFS is O(V+E),
Where V is the number of nodes and
E is the number of edges.
program on BFS graph traversal :
An undirected and connected graph
G=(V,E), a spanning tree of the graph G is a
tree that spans G (that is, it includes every
vertex of G) and is a sub-graph of G (every
edge in the tree belongs to G).
The cost of the spanning tree is the sum of the
weights of all the edges in the tree. There can be
many spanning trees. Minimum spanning tree is
the spanning tree where the cost is minimum
among all the spanning trees. There also can be
many minimum spanning trees.
Minimum spanning tree has direct application
in the design of networks. It is used in algorithms
approximating the travelling salesman problem,
multi-terminal minimum cut problem and
minimum-cost weighted perfect matching.
1 2
3 4
3
1 2
3 4
1 2
4
2
4
1
3
1
4
2
43
2
Cost=7(2+4+1)
Cost=9(2+4+3)
1
There are two famous algorithms for
finding the Minimum Spanning Tree (MST ) :
1) Kruskal’s Algorithm
2) Prim’s Algorithm
Kruskal’s Algorithm builds the spanning
tree by adding edges one by one into a
growing spanning tree. Kruskal's algorithm
follows greedy approach as in each iteration
it finds an edge which has least weight and
add it to the growing spanning tree.
Algorithm Steps:
 Sort the graph edges with respect to their
weights.
 Start adding edges to the MST from the edge
with the smallest weight until the edge of the
largest weight.
 Only add edges which doesn't form a cycle ,
edges which connect only disconnected
components.
So now the question is how to check
if 2 vertices are connected or not ?
This could be done using DFS which starts
from the first vertex, then check if the second
vertex is visited or not. But DFS will make time
complexity large as it has an order
of O(V+E) where V is the number of vertices, E is
the number of edges. So the best solution
is "Disjoint Sets":
Disjoint sets are sets whose intersection is the
empty set so it means that they don't have any
element in common.
This MST’s total cost
11(=1+2+3+5)
Prim’s Algorithm also use Greedy
approach to find the minimum spanning tree.
In Prim’s Algorithm we grow the spanning
tree from a starting position. Unlike
an edge in Kruskal's, we add vertex to the
growing spanning tree in Prim's.
Algorithm Steps:
 Maintain two disjoint sets of vertices. One containing
vertices that are in the growing spanning tree and
other that are not in the growing spanning tree.
 Select the cheapest vertex that is connected to the
growing spanning tree and is not in the growing
spanning tree and add it into the growing spanning
tree. This can be done using Priority Queues. Insert
the vertices, that are connected to growing spanning
tree, into the Priority Queue.
 Check for cycles. To do that, mark the nodes which
have been already selected and insert only those
nodes in the Priority Queue that are not marked.
The MST of total
cost 7 ( = 1 + 2 +4).
 Time Complexity of kruskal’s algorithm:
In Kruskal’s algorithm, most time consuming
operation is sorting because the total complexity
of the Disjoint-Set operations will be O(E logV),
which is the overall Time Complexity of the
algorithm.
 Time Complexity of prim’s algorithm:
The time complexity of the Prim’s Algorithm
is O((V+E) logV) because each vertex is inserted
in the priority queue only once and insertion in
priority queue take logarithmic time.
 A graph is a non-linear data structure, which
consist of vertices (or nodes) connected by
edges (or arcs)where edges may be directed
or undirected.
 In computer science graphs are used to
represent the flow of computation.
 Thus the development of algorithm to handle
graphs is of major interest in the field of
computer science.
1. Social network graphs :-An example twitter
and face-book graph of who follows whom .
this can be use determine how information
flows.
2. Transportation network :-In road network
and public transportation vertices are stops
and edges are the links between them.
3. Utility graphs :-The power grid , the internet
and the water network are all example of
graphs where vertices connection points and
edges the wires or pipes between them.
4. Document link graph :-The best known
example is the link graph of the web where
each web page is a vertex and each
hyperlink a directed edge.
5. Protein –protein graph :-Vertices represent
proteins and edges represent interaction
between them that carry our some biological
function in the cell.
6. Network packet traffic graphs :-Vertices are
IP(internet protocol) address an a edges are
the packets that flow between them.
7. Scene graph :- In graphics and computer
games scene graphs represent the logical or
special relationships between objects in a
scene .such graph very important in the
computer game industry.
8. Semantic network :-Vertices represents
words or concepts and edges represent the
relationship among the words or concepts.
Graph Data Structures and Algorithms

More Related Content

What's hot

Adjacency list
Adjacency listAdjacency list
Adjacency listStefi Yu
 
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
 
Applications of graphs
Applications of graphsApplications of graphs
Applications of graphsTech_MX
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structureIkhlas Rahman
 
Attributed Graph Matching of Planar Graphs
Attributed Graph Matching of Planar GraphsAttributed Graph Matching of Planar Graphs
Attributed Graph Matching of Planar GraphsRaül Arlàndez
 
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
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graphRounak Biswas
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1Tech_MX
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1David Wood
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory IntroductionMANISH T I
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 

What's hot (20)

Adjacency list
Adjacency listAdjacency list
Adjacency list
 
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
 
Applications of graphs
Applications of graphsApplications of graphs
Applications of graphs
 
Graphs in Data Structure
Graphs in Data StructureGraphs in Data Structure
Graphs in Data Structure
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graph algorithms
Graph algorithmsGraph algorithms
Graph algorithms
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Data structure
Data structureData structure
Data structure
 
Planar graph
Planar graphPlanar graph
Planar graph
 
Graph
GraphGraph
Graph
 
Attributed Graph Matching of Planar Graphs
Attributed Graph Matching of Planar GraphsAttributed Graph Matching of Planar Graphs
Attributed Graph Matching of Planar Graphs
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
 
Data Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneData Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZone
 
Matrix representation of graph
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory Introduction
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 

Similar to Graph Data Structures and Algorithms

Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx pptDhruvilSTATUS
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programMuhammad Danish Badar
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdfamitbhachne
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxking779879
 
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
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxwhittemorelucilla
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxasimshahzad8611
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxbashirabdullah789
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
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
 

Similar to Graph Data Structures and Algorithms (20)

Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Graph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptxGraph_data_structure_information_engineering.pptx
Graph_data_structure_information_engineering.pptx
 
Unit V - ppt.pptx
Unit V - ppt.pptxUnit V - ppt.pptx
Unit V - ppt.pptx
 
Graphs
GraphsGraphs
Graphs
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
Data structure and algorithm
Data structure and algorithmData structure and algorithm
Data structure and algorithm
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Graph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptxGraph Representation, DFS and BFS Presentation.pptx
Graph Representation, DFS and BFS Presentation.pptx
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
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
 

Recently uploaded

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Graph Data Structures and Algorithms

  • 2. Submitted To : Dr. Pooja Shrimali Submitted By : Komal Paliwal & Jitendra Bhatia
  • 3.
  • 4.
  • 5. GRAPH is non-linear data structure, it contains a set of points known as Nodes(or Vertices) and set of links known as Edges(or Arcs) which connect the vertices. A graph is defined as follows.... “Graph is a collection of nodes and edges which connects vertices in the graph.” Generally, a graph G is represented as G=( V , E ), where V is set of vertices and E is set of edges.
  • 6. The following is a graph with 5 vertices and 6 edges. This graph G can be defined as G =( V , E ). Where V= {A,B,C,D,E} and E={(A,B),(A,C),(A,D),(B,D),(C,D),(B,E),(E,D)}. Edges Vertices A B C D E
  • 7. We use the following term in data structure...........  Vertex  Edges a. Undirected graph b. Directed graph c. Weighted graph  Undirected graph  Directed graph  Mixed graph  End vertices or End points  Origin Description of these terminology’s.  Destination  Adjacent  Incident  Outgoing Edge  Incoming Edge  Degree  In Degree  Out degree  Parallel edges or Multiple edges  Self loop  Simple graph  Path
  • 8. Graph data structure is represented using following representations..... 1. Adjacency Matrix 2. Incidence Matrix 3. Adjacency List
  • 9. In this representation, graph can be represented using a matrix of size total number of vertices by total number of vertices. That means if a graph with 4 vertices can be represents vertices. This matrix is filled with either 1 or 0. here, 1 represents there is an edge from row vertex to column vertex and o represents there is no edge from vertex to column vertex.
  • 10. A B E C D A C B D E Undirected graph Directed graph A B C D E A B C D E 0 1 1 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 1 1 0 1 0 1 0 A B C D E A B C D E 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 0 For example :-
  • 11. In this representation, graph can be represented using a matrix of size total number of vertices by total number of edges. That means if a graph with 4 vertices and 6 edges can be represented using a matrix of 4x6 class. In this matrix, rows represents vertices and columns represents edges. This matrix is filled with either 0 or 1 or -1. here, o represents row edge is not connected to column vertex, 1 represents row edge is connected as outgoing edge to column vertex and -1 represents row edge is connected as incoming edge to column vertex.
  • 12. E1 E2 E3 E4 E5 E6 E7 E8 A B C D E 1 -1 0 0 0 1 0 -1 0 0 -1 0 0 1 0 0 1 0 -1 0 0 0 1 -1 0 0 0 0 1 -1 0 1 0 0 -1 0 0 0 1 0 A DC B E E1 E3 E7 E6 E4E2 E5 E8 For example :-
  • 13. In this representation, every vertex of graph contains list of its adjacent vertices. For example :-This representation can also be implemented using array as follows... Reference Array Adjacency Array E A B C D 0 1 2 3 4 B C D E D A D E
  • 14. For example, consider the following directed graph representation implemented using linked list.... E BA DC A B C D E E E D B D D A C
  • 15. Graph traversals 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 is also 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.
  • 16. There are two traversal techniques and they are as follows… 1. Depth First Traversal (D F S) 2. Breadth First Traversal (B F S)
  • 17. 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.
  • 18. 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 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 tracking and pop one vertex from the stack. Step 6: Repeat steps 3,4and5 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.
  • 19. Consider the following example graph to perform DFS traversal : DFS traversal on this example: A B DC E
  • 20. 1. For an unweighted graph 2. Detecting cycle in a graph 3. Path finding 4. Topological sorting 5. Finding strongly connected component of a graph 6. Solving puzzles with only one solution(such as mazes).
  • 21.  For an unweighted graph, DFS traversal of the graph produces the minimum spanning tree and all pair shortest path tree.  Detecting cycle in a graph, A graph has cycle if and if we see a back edge during DFS. So we can run DFS for the graph and check for back edges.  Path finding, We can specialize the DFS algorithm to find a path between two given vertices u and z.  Call DFS(G,u)with u as the start vertex.  Use a stack S to keep track of the path between the start vertex and the current vertex.  As soon as destination vertex z is encountered, return the path as the contents of the stack
  • 22. DFS-iterative(G,s): //Where G is graph and s is source vertex. let S be stack s.push(s) marks s as visited while(S is not empty); //Pop a vertex from stack to visit next v=S.top( ) S.pop( ) //Push all the neighbours of v in stack that are not visited for all neighbors w of v in Graph G: if w is not visited : s.push(w) mark w as visited
  • 23. The time complexity of DFS is O(V+E), Where V is the number of nodes and E is the number of edges. Program of Depth First Traversal :
  • 24. Breadth first search(BFS) algorithm traverses a graph in a breadth ward motion and uses a queue to remember to get the next vertex to start a search, when a dead end occurs in any iteration. It employs the following rules : Rule1 :Visit the adjacent vertex. Mark it as visited. Display it. Insert it in a queue. Rule2 :If no adjacent vertex is found , remove the vertex from the queue. Rule3 :Repeat Rule1 and Rule 2 till the queue is empty.
  • 25. Consider the following example graph to perform BFS traversal : BFS traversal on this example : S BA C D
  • 26. BFS(G,s) //where G is a graph and s is the source node let Q be queue. Q.enqueue(s) //Inserting s in queue until its neighbour vertices are marked. marks s as visited. while(Q is not empty) //Removing that vertex from queue, whose neighbour will be visited now v=Q.dequeue( ) //processing all the neighbours of v for all neighbours w of v in Graph G if w is not visited Q.enqueue(w) // Stores w in Q to further visit its neighbour mark w as visited.
  • 27. The time complexity of BFS is O(V+E), Where V is the number of nodes and E is the number of edges. program on BFS graph traversal :
  • 28. An undirected and connected graph G=(V,E), a spanning tree of the graph G is a tree that spans G (that is, it includes every vertex of G) and is a sub-graph of G (every edge in the tree belongs to G).
  • 29. The cost of the spanning tree is the sum of the weights of all the edges in the tree. There can be many spanning trees. Minimum spanning tree is the spanning tree where the cost is minimum among all the spanning trees. There also can be many minimum spanning trees. Minimum spanning tree has direct application in the design of networks. It is used in algorithms approximating the travelling salesman problem, multi-terminal minimum cut problem and minimum-cost weighted perfect matching.
  • 30. 1 2 3 4 3 1 2 3 4 1 2 4 2 4 1 3 1 4 2 43 2 Cost=7(2+4+1) Cost=9(2+4+3) 1
  • 31. There are two famous algorithms for finding the Minimum Spanning Tree (MST ) : 1) Kruskal’s Algorithm 2) Prim’s Algorithm
  • 32. Kruskal’s Algorithm builds the spanning tree by adding edges one by one into a growing spanning tree. Kruskal's algorithm follows greedy approach as in each iteration it finds an edge which has least weight and add it to the growing spanning tree.
  • 33. Algorithm Steps:  Sort the graph edges with respect to their weights.  Start adding edges to the MST from the edge with the smallest weight until the edge of the largest weight.  Only add edges which doesn't form a cycle , edges which connect only disconnected components.
  • 34. So now the question is how to check if 2 vertices are connected or not ? This could be done using DFS which starts from the first vertex, then check if the second vertex is visited or not. But DFS will make time complexity large as it has an order of O(V+E) where V is the number of vertices, E is the number of edges. So the best solution is "Disjoint Sets": Disjoint sets are sets whose intersection is the empty set so it means that they don't have any element in common.
  • 35. This MST’s total cost 11(=1+2+3+5)
  • 36. Prim’s Algorithm also use Greedy approach to find the minimum spanning tree. In Prim’s Algorithm we grow the spanning tree from a starting position. Unlike an edge in Kruskal's, we add vertex to the growing spanning tree in Prim's.
  • 37. Algorithm Steps:  Maintain two disjoint sets of vertices. One containing vertices that are in the growing spanning tree and other that are not in the growing spanning tree.  Select the cheapest vertex that is connected to the growing spanning tree and is not in the growing spanning tree and add it into the growing spanning tree. This can be done using Priority Queues. Insert the vertices, that are connected to growing spanning tree, into the Priority Queue.  Check for cycles. To do that, mark the nodes which have been already selected and insert only those nodes in the Priority Queue that are not marked.
  • 38. The MST of total cost 7 ( = 1 + 2 +4).
  • 39.  Time Complexity of kruskal’s algorithm: In Kruskal’s algorithm, most time consuming operation is sorting because the total complexity of the Disjoint-Set operations will be O(E logV), which is the overall Time Complexity of the algorithm.  Time Complexity of prim’s algorithm: The time complexity of the Prim’s Algorithm is O((V+E) logV) because each vertex is inserted in the priority queue only once and insertion in priority queue take logarithmic time.
  • 40.  A graph is a non-linear data structure, which consist of vertices (or nodes) connected by edges (or arcs)where edges may be directed or undirected.  In computer science graphs are used to represent the flow of computation.  Thus the development of algorithm to handle graphs is of major interest in the field of computer science.
  • 41. 1. Social network graphs :-An example twitter and face-book graph of who follows whom . this can be use determine how information flows. 2. Transportation network :-In road network and public transportation vertices are stops and edges are the links between them. 3. Utility graphs :-The power grid , the internet and the water network are all example of graphs where vertices connection points and edges the wires or pipes between them.
  • 42. 4. Document link graph :-The best known example is the link graph of the web where each web page is a vertex and each hyperlink a directed edge. 5. Protein –protein graph :-Vertices represent proteins and edges represent interaction between them that carry our some biological function in the cell. 6. Network packet traffic graphs :-Vertices are IP(internet protocol) address an a edges are the packets that flow between them.
  • 43. 7. Scene graph :- In graphics and computer games scene graphs represent the logical or special relationships between objects in a scene .such graph very important in the computer game industry. 8. Semantic network :-Vertices represents words or concepts and edges represent the relationship among the words or concepts.