SlideShare a Scribd company logo
1 of 28
Download to read offline
GRAPH
Types of Graph
Terminology
Storage Structure
1
Graph
2
A graph is a collection of nodes (or vertices, singular is
vertex) and edges (or arcs)
 Each node contains an element
 Each edge connects two nodes together (or
possibly the same node to itself) and may
contain an edge attribute A
B
G
E
F
D
C
Formal definition of graph
3
A graph G is defined as follows:
G=(V,E)
V(G): a finite, nonempty set of vertices
E(G): a set of edges (pairs of vertices)
Types of graph
Directed graph (digraph)
Undirected graph (graph)
4
Undirected graph
5
 An undirected graph is one in
which the edges do not have a
direction
 ‘graph’ denotes undirected graph.
 Undirected graph:
 ( v1, v2 ) in E is un-ordered.
 (v1,v2) and (v2, v1) represent
the same edge.
G1 = ( 4, 6)
V(G1) = { 0, 1, 2 , 3 }
E(G1) = { (0,1), (0,2), (0,3
(1,2), (1,3), (2,3) }
 Directed graph is one in which the
edges have a direction
 Also called as ‘digraph’
 Directed graph:
 < v1, v2 > in E is ordered.
 <V1,v2> and <v2, v1> represent
the two different edges.
6
G3 = (3, 3)
V(G3) = { 0,1,2 }
E(G3) = { <0,1> , <1,0> , <1,2>
Directed graph
7
A complete graph is a graph that has the maximum
number of edges .
 for undirected graph with n vertices, the
maximum number of edges is n(n-1)/2
 for directed graph with n vertices, the
maximum number of edges is n(n-1)
Complete graph
8
No.of edges = n(n-1)/2
= 4*3/2
= 12/2
= 6
No.of edges = n(n-1)/2
= 7*6/2
= 42/2
= 21
No.of edges = n(n-1
= 3*2
= 6
Complete graph
Adjacent and Incident
9
 If (v0, v1) is an edge in an undirected graph,
– v0 and v1 are adjacent
– The edge (v0, v1) is incident on vertices v0 and v1
 If <v0, v1> is an edge in a directed graph
– v0 is adjacent to v1, and v1 is adjacent from v0
– The edge <v0, v1> is incident on vertices v0 and v1
Sub- graph
A sub-graph of G is a graph G’ such that
 V(G’) is a subset of V(G)
 E(G’) is a subset of E(G)
10
Path
11
 A path is a list of edges such that each node is the
predecessor of the next node in the list
 A path from vertex vp to vertex vq in a graph G, is a
sequence of vertices, vp, vi1, vi2, ..., vin, vq, such that
(vp, vi1), (vi1, vi2), ..., (vin, vq) are edges in an
undirected graph
 The length of a path is the number of edges on it
 A simple path is a path in which all vertices,
except possibly the first and the last, are distinct
Cycle
12
A cycle is a path whose first and last nodes are the
same
- A cyclic graph contains at least one cycle
- An acyclic graph does not contain any cycles
cyclic graph acyclic graph
Connected component
 In an undirected graph G, two vertices, v0 and v1,
are connected if there is a path in G from v0 to v1
 An undirected graph is connected if, for every pair
of distinct vertices vi, vj, there is a path from vi to vj
 A connected component of an undirected graph is a
maximal connected sub-graph.
13
Strongly connected
 A directed graph is strongly connected if there is a
directed path from vi to vj and also from vj to vi.
 A strongly connected component is a maximal sub-
graph that is strongly connected
14
Tree
A tree is a graph that is
 connected
 acyclic.
15
Degree
16
 The degree of a vertex is the number of edges incident
to that vertex
 For directed graph,
 the in-degree of a vertex v is the number of
edges that have v as the head
 the out-degree of a vertex v is the number of
edges that have v as the tail
 if di is the degree of a vertex i in a graph G with
n vertices and e edges, the number of edges is
2/)(
1
0



n
ide
Degree - graph
17
Degree - digraph
18
Graph Representation
19
 Adjacency Matrix
 Adjacency Lists
Adjacency matrix
20
 Let G=(V,E) be a graph with n vertices.
 The adjacency matrix of G is a two-dimensional
n by n array, say adj_mat
 If the edge (vi, vj) is in E(G), adj_mat[i][j]=1
 If there is no edge in E(G), adj_mat[i][j]=0
 The adjacency matrix for an undirected graph is
symmetric
 the adjacency matrix for a digraph need not be
symmetric
Adjacency matrix - graph
21
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
0












0 1 2 3
0
1
2
3
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
7
Adjacency matrix - digraph
22
0
1
0
1
0
0
0
1
0










0 1 2
0
1
2
23
 From the adjacency matrix, to determine the connection
of vertices is easy
 The degree of a vertex is
 For a digraph,
 the row sum is the out_degree
 the column sum is the in_degree
Merits of Adjacency Matrix
adj mat i j
j
n
_ [ ][ ]


0
1
ind vi A j i
j
n
( ) [ , ]



0
1
outd vi A i j
j
n
( ) [ , ]



0
1
Demerits of adjacency matrix
24
 Storage complexity: O(|V|2)
 Difficult to insert and delete nodes.
Adjacency list
25
 To overcome the problem arise in the adjacency
matrix, linked list can be used
 The adjacency list contains two lists
1. node list
2. edge list
Adjacency list – graph
26
Adjacency list - digraph
27
Adjacency list Inverse Adjacency
list
Merits of adjacency list
28
 degree of a vertex in an undirected graph
 number of nodes in adjacency list
 out-degree of a vertex in a directed graph
 number of nodes in its adjacency list
 in-degree of a vertex in a directed graph
 traverse the whole data structure
 Simple way to find out in-degree of vertex in a directed
graph
 Represent the graph in inverse adjacency list

More Related Content

What's hot

What's hot (20)

Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
 
Hashing
HashingHashing
Hashing
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Heaps
HeapsHeaps
Heaps
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 

Viewers also liked

Adjacency list
Adjacency listAdjacency list
Adjacency listStefi Yu
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structurehafsa komal
 
Graph data structure
Graph data structureGraph data structure
Graph data structureTech_MX
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Simple graph types
Simple graph typesSimple graph types
Simple graph typesMahi Syama
 
Types of graphs
Types of graphsTypes of graphs
Types of graphsbweldon
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015Aysylu Greenberg
 
Path cycle part1
Path cycle part1Path cycle part1
Path cycle part1guestb63941
 
Choosing Graph and Chart types
Choosing Graph and Chart typesChoosing Graph and Chart types
Choosing Graph and Chart typesiteclearners
 
Intro to statistics
Intro to statisticsIntro to statistics
Intro to statisticsUlster BOCES
 
2014 welcome to math 6. t mc comb
2014 welcome to math 6. t mc comb2014 welcome to math 6. t mc comb
2014 welcome to math 6. t mc combtamcc
 

Viewers also liked (20)

Adjacency list
Adjacency listAdjacency list
Adjacency list
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Graph data structure
Graph  data structureGraph  data structure
Graph data structure
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Simple graph types
Simple graph typesSimple graph types
Simple graph types
 
Types of graphs
Types of graphsTypes of graphs
Types of graphs
 
Graphs ppt
Graphs pptGraphs ppt
Graphs ppt
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015
 
Path cycle part1
Path cycle part1Path cycle part1
Path cycle part1
 
Statistics: Graph(grouped data)
Statistics: Graph(grouped data)Statistics: Graph(grouped data)
Statistics: Graph(grouped data)
 
Chp 4
Chp 4Chp 4
Chp 4
 
Choosing Graph and Chart types
Choosing Graph and Chart typesChoosing Graph and Chart types
Choosing Graph and Chart types
 
Intro to statistics
Intro to statisticsIntro to statistics
Intro to statistics
 
2014 welcome to math 6. t mc comb
2014 welcome to math 6. t mc comb2014 welcome to math 6. t mc comb
2014 welcome to math 6. t mc comb
 
Percentage
PercentagePercentage
Percentage
 

Similar to Graph Data Structure Types

Similar to Graph Data Structure Types (20)

graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Graphs
GraphsGraphs
Graphs
 
Graph-theory.ppt
Graph-theory.pptGraph-theory.ppt
Graph-theory.ppt
 
Graph.ppt
Graph.pptGraph.ppt
Graph.ppt
 
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsFallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
 
Dsa.PPT
Dsa.PPTDsa.PPT
Dsa.PPT
 
chapter6.PPT
chapter6.PPTchapter6.PPT
chapter6.PPT
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
 
Chapter 1
Chapter   1Chapter   1
Chapter 1
 
Elements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
 
Graph terminologies & special type graphs
Graph terminologies & special type graphsGraph terminologies & special type graphs
Graph terminologies & special type graphs
 
Graph
GraphGraph
Graph
 
Graph theory
Graph theoryGraph theory
Graph theory
 
DATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptxDATA STRUCTURES unit 4.pptx
DATA STRUCTURES unit 4.pptx
 
Graphs
GraphsGraphs
Graphs
 
Ass. (3)graph d.m
Ass. (3)graph d.mAss. (3)graph d.m
Ass. (3)graph d.m
 
Graph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptxGraph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptx
 
Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 

More from Madhu Bala

Internet of Things (IoT)
Internet of Things (IoT)Internet of Things (IoT)
Internet of Things (IoT)Madhu Bala
 
Operating system
Operating systemOperating system
Operating systemMadhu Bala
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)Madhu Bala
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
GPRS Technology
GPRS TechnologyGPRS Technology
GPRS TechnologyMadhu Bala
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - IntroductionMadhu Bala
 
Smoothing Filters in Spatial Domain
Smoothing Filters in Spatial DomainSmoothing Filters in Spatial Domain
Smoothing Filters in Spatial DomainMadhu Bala
 

More from Madhu Bala (10)

Internet of Things (IoT)
Internet of Things (IoT)Internet of Things (IoT)
Internet of Things (IoT)
 
Digital logic
Digital logicDigital logic
Digital logic
 
Operating system
Operating systemOperating system
Operating system
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
GPRS Technology
GPRS TechnologyGPRS Technology
GPRS Technology
 
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
 
4G technology
4G technology4G technology
4G technology
 
Smoothing Filters in Spatial Domain
Smoothing Filters in Spatial DomainSmoothing Filters in Spatial Domain
Smoothing Filters in Spatial Domain
 

Recently uploaded

What is Property Fields in Odoo 17 ERP Module
What is Property Fields in Odoo 17 ERP ModuleWhat is Property Fields in Odoo 17 ERP Module
What is Property Fields in Odoo 17 ERP ModuleCeline George
 
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...Nguyen Thanh Tu Collection
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfChristalin Nelson
 
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdfMJDuyan
 
Views in Odoo 17 - Kanban View in odoo 17
Views in Odoo 17 - Kanban View  in odoo 17Views in Odoo 17 - Kanban View  in odoo 17
Views in Odoo 17 - Kanban View in odoo 17Celine George
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...EduSkills OECD
 
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdfMJDuyan
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 
How to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPHow to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPCeline George
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...Nguyen Thanh Tu Collection
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
4.4.24 Economic Precarity and Global Economic Forces.pptx
4.4.24 Economic Precarity and Global Economic Forces.pptx4.4.24 Economic Precarity and Global Economic Forces.pptx
4.4.24 Economic Precarity and Global Economic Forces.pptxmary850239
 
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024St.John's College
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF NAT...
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF  NAT...LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF  NAT...
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF NAT...pragatimahajan3
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Osopher
 
Executive Directors Chat Initiating Equity for Impact.pdf
Executive Directors Chat  Initiating Equity for Impact.pdfExecutive Directors Chat  Initiating Equity for Impact.pdf
Executive Directors Chat Initiating Equity for Impact.pdfTechSoup
 

Recently uploaded (20)

What is Property Fields in Odoo 17 ERP Module
What is Property Fields in Odoo 17 ERP ModuleWhat is Property Fields in Odoo 17 ERP Module
What is Property Fields in Odoo 17 ERP Module
 
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...
BÀI TẬP BỔ TRỢ 4 KĨ NĂNG TIẾNG ANH LỚP 8 - CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC ...
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdf
 
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 3) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
 
Views in Odoo 17 - Kanban View in odoo 17
Views in Odoo 17 - Kanban View  in odoo 17Views in Odoo 17 - Kanban View  in odoo 17
Views in Odoo 17 - Kanban View in odoo 17
 
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
Advancing Gender Equality The Crucial Role of Science and Technology 4 April ...
 
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
(Part 2) CHILDREN'S DISABILITIES AND EXCEPTIONALITIES.pdf
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 
How to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERPHow to Share Dashboard in the Odoo 17 ERP
How to Share Dashboard in the Odoo 17 ERP
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - I-LEARN SMART WORLD - CẢ NĂM - CÓ FILE NGHE (BẢN...
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
4.4.24 Economic Precarity and Global Economic Forces.pptx
4.4.24 Economic Precarity and Global Economic Forces.pptx4.4.24 Economic Precarity and Global Economic Forces.pptx
4.4.24 Economic Precarity and Global Economic Forces.pptx
 
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024
Basic cosmetics prepared by my student Mr. Balamurugan, II Maths, 2023-2024
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF NAT...
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF  NAT...LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF  NAT...
LEVERAGING SYNERGISM INDUSTRY-ACADEMIA PARTNERSHIP FOR IMPLEMENTATION OF NAT...
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
 
Executive Directors Chat Initiating Equity for Impact.pdf
Executive Directors Chat  Initiating Equity for Impact.pdfExecutive Directors Chat  Initiating Equity for Impact.pdf
Executive Directors Chat Initiating Equity for Impact.pdf
 

Graph Data Structure Types

  • 2. Graph 2 A graph is a collection of nodes (or vertices, singular is vertex) and edges (or arcs)  Each node contains an element  Each edge connects two nodes together (or possibly the same node to itself) and may contain an edge attribute A B G E F D C
  • 3. Formal definition of graph 3 A graph G is defined as follows: G=(V,E) V(G): a finite, nonempty set of vertices E(G): a set of edges (pairs of vertices)
  • 4. Types of graph Directed graph (digraph) Undirected graph (graph) 4
  • 5. Undirected graph 5  An undirected graph is one in which the edges do not have a direction  ‘graph’ denotes undirected graph.  Undirected graph:  ( v1, v2 ) in E is un-ordered.  (v1,v2) and (v2, v1) represent the same edge. G1 = ( 4, 6) V(G1) = { 0, 1, 2 , 3 } E(G1) = { (0,1), (0,2), (0,3 (1,2), (1,3), (2,3) }
  • 6.  Directed graph is one in which the edges have a direction  Also called as ‘digraph’  Directed graph:  < v1, v2 > in E is ordered.  <V1,v2> and <v2, v1> represent the two different edges. 6 G3 = (3, 3) V(G3) = { 0,1,2 } E(G3) = { <0,1> , <1,0> , <1,2> Directed graph
  • 7. 7 A complete graph is a graph that has the maximum number of edges .  for undirected graph with n vertices, the maximum number of edges is n(n-1)/2  for directed graph with n vertices, the maximum number of edges is n(n-1) Complete graph
  • 8. 8 No.of edges = n(n-1)/2 = 4*3/2 = 12/2 = 6 No.of edges = n(n-1)/2 = 7*6/2 = 42/2 = 21 No.of edges = n(n-1 = 3*2 = 6 Complete graph
  • 9. Adjacent and Incident 9  If (v0, v1) is an edge in an undirected graph, – v0 and v1 are adjacent – The edge (v0, v1) is incident on vertices v0 and v1  If <v0, v1> is an edge in a directed graph – v0 is adjacent to v1, and v1 is adjacent from v0 – The edge <v0, v1> is incident on vertices v0 and v1
  • 10. Sub- graph A sub-graph of G is a graph G’ such that  V(G’) is a subset of V(G)  E(G’) is a subset of E(G) 10
  • 11. Path 11  A path is a list of edges such that each node is the predecessor of the next node in the list  A path from vertex vp to vertex vq in a graph G, is a sequence of vertices, vp, vi1, vi2, ..., vin, vq, such that (vp, vi1), (vi1, vi2), ..., (vin, vq) are edges in an undirected graph  The length of a path is the number of edges on it  A simple path is a path in which all vertices, except possibly the first and the last, are distinct
  • 12. Cycle 12 A cycle is a path whose first and last nodes are the same - A cyclic graph contains at least one cycle - An acyclic graph does not contain any cycles cyclic graph acyclic graph
  • 13. Connected component  In an undirected graph G, two vertices, v0 and v1, are connected if there is a path in G from v0 to v1  An undirected graph is connected if, for every pair of distinct vertices vi, vj, there is a path from vi to vj  A connected component of an undirected graph is a maximal connected sub-graph. 13
  • 14. Strongly connected  A directed graph is strongly connected if there is a directed path from vi to vj and also from vj to vi.  A strongly connected component is a maximal sub- graph that is strongly connected 14
  • 15. Tree A tree is a graph that is  connected  acyclic. 15
  • 16. Degree 16  The degree of a vertex is the number of edges incident to that vertex  For directed graph,  the in-degree of a vertex v is the number of edges that have v as the head  the out-degree of a vertex v is the number of edges that have v as the tail  if di is the degree of a vertex i in a graph G with n vertices and e edges, the number of edges is 2/)( 1 0    n ide
  • 19. Graph Representation 19  Adjacency Matrix  Adjacency Lists
  • 20. Adjacency matrix 20  Let G=(V,E) be a graph with n vertices.  The adjacency matrix of G is a two-dimensional n by n array, say adj_mat  If the edge (vi, vj) is in E(G), adj_mat[i][j]=1  If there is no edge in E(G), adj_mat[i][j]=0  The adjacency matrix for an undirected graph is symmetric  the adjacency matrix for a digraph need not be symmetric
  • 21. Adjacency matrix - graph 21 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0             0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  • 22. Adjacency matrix - digraph 22 0 1 0 1 0 0 0 1 0           0 1 2 0 1 2
  • 23. 23  From the adjacency matrix, to determine the connection of vertices is easy  The degree of a vertex is  For a digraph,  the row sum is the out_degree  the column sum is the in_degree Merits of Adjacency Matrix adj mat i j j n _ [ ][ ]   0 1 ind vi A j i j n ( ) [ , ]    0 1 outd vi A i j j n ( ) [ , ]    0 1
  • 24. Demerits of adjacency matrix 24  Storage complexity: O(|V|2)  Difficult to insert and delete nodes.
  • 25. Adjacency list 25  To overcome the problem arise in the adjacency matrix, linked list can be used  The adjacency list contains two lists 1. node list 2. edge list
  • 26. Adjacency list – graph 26
  • 27. Adjacency list - digraph 27 Adjacency list Inverse Adjacency list
  • 28. Merits of adjacency list 28  degree of a vertex in an undirected graph  number of nodes in adjacency list  out-degree of a vertex in a directed graph  number of nodes in its adjacency list  in-degree of a vertex in a directed graph  traverse the whole data structure  Simple way to find out in-degree of vertex in a directed graph  Represent the graph in inverse adjacency list

Editor's Notes

  1. Inverse adjacenecy list – determine in-degree fast