Data structure - Graph

Madhu Bala
Madhu BalaAssistant Profesoor en TMM college of Arts and Sciene
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
1 de 28

Recomendados

Graph in data structure por
Graph in data structureGraph in data structure
Graph in data structureAbrish06
42.9K vistas24 diapositivas
Graphs in data structure por
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
1.8K vistas32 diapositivas
Graph data structure and algorithms por
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithmsAnandhasilambarasan D
2.2K vistas10 diapositivas
Graph representation por
Graph representationGraph representation
Graph representationTech_MX
37.2K vistas34 diapositivas
linked list in data structure por
linked list in data structure linked list in data structure
linked list in data structure shameen khan
39.1K vistas63 diapositivas
Graph traversals in Data Structures por
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data StructuresAnandhasilambarasan D
4.4K vistas11 diapositivas

Más contenido relacionado

La actualidad más candente

Tree traversal techniques por
Tree traversal techniquesTree traversal techniques
Tree traversal techniquesSyed Zaid Irshad
3.1K vistas34 diapositivas
Binary Tree in Data Structure por
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
559 vistas23 diapositivas
Binary Search Tree in Data Structure por
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
35.8K vistas126 diapositivas
sparse matrix in data structure por
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structureMAHALAKSHMI P
2.5K vistas9 diapositivas
Tree - Data Structure por
Tree - Data StructureTree - Data Structure
Tree - Data StructureAshim Lamichhane
59.8K vistas63 diapositivas
Dijkstra por
DijkstraDijkstra
Dijkstrajagdeeparora86
6.6K vistas22 diapositivas

La actualidad más candente(20)

Binary Tree in Data Structure por Meghaj Mallick
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick559 vistas
Binary Search Tree in Data Structure por Dharita Chokshi
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi35.8K vistas
sparse matrix in data structure por MAHALAKSHMI P
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P2.5K vistas
1.1 binary tree por Krish_ver2
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver218.3K vistas
Data Structures - Lecture 9 [Stack & Queue using Linked List] por Muhammad Hammad Waseem
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
B trees in Data Structure por Anuj Modi
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
Anuj Modi53.5K vistas
Linked list por akshat360
Linked listLinked list
Linked list
akshat36085.8K vistas
trees in data structure por shameen khan
trees in data structure trees in data structure
trees in data structure
shameen khan3.5K vistas
Graph Basic In Data structure por Ikhlas Rahman
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
Ikhlas Rahman2.1K vistas
Trees data structure por Sumit Gupta
Trees data structureTrees data structure
Trees data structure
Sumit Gupta19.4K vistas
Graphs in Data Structure por hafsa komal
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
hafsa komal2.2K vistas

Destacado

Graphs In Data Structure por
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
45.6K vistas32 diapositivas
Adjacency list por
Adjacency listAdjacency list
Adjacency listStefi Yu
4.5K vistas15 diapositivas
Graph data structure por
Graph data structureGraph data structure
Graph data structureTech_MX
14.1K vistas28 diapositivas
Graph data structure por
Graph  data structureGraph  data structure
Graph data structureFâhém Ähmêd
1.8K vistas18 diapositivas
Data structure computer graphs por
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
4.4K vistas22 diapositivas

Destacado(20)

Graphs In Data Structure por Anuj Modi
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi45.6K vistas
Adjacency list por Stefi Yu
Adjacency listAdjacency list
Adjacency list
Stefi Yu4.5K vistas
Graph data structure por Tech_MX
Graph data structureGraph data structure
Graph data structure
Tech_MX14.1K vistas
Data structure computer graphs por Kumar
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar 4.4K vistas
Simple graph types por Mahi Syama
Simple graph typesSimple graph types
Simple graph types
Mahi Syama2.9K vistas
Types of graphs por bweldon
Types of graphsTypes of graphs
Types of graphs
bweldon23.4K vistas
Graphs ppt por aimorales
Graphs pptGraphs ppt
Graphs ppt
aimorales52.2K vistas
DATA STRUCTURES por bca2010
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca201096.8K vistas
Loom & Functional Graphs in Clojure @ LambdaConf 2015 por Aysylu Greenberg
Loom & Functional Graphs in Clojure @ LambdaConf 2015Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015
Aysylu Greenberg3.1K vistas
Choosing Graph and Chart types por iteclearners
Choosing Graph and Chart typesChoosing Graph and Chart types
Choosing Graph and Chart types
iteclearners1.3K vistas
Intro to statistics por Ulster BOCES
Intro to statisticsIntro to statistics
Intro to statistics
Ulster BOCES1.6K vistas
2014 welcome to math 6. t mc comb por tamcc
2014 welcome to math 6. t mc comb2014 welcome to math 6. t mc comb
2014 welcome to math 6. t mc comb
tamcc2.2K vistas
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W2 Non Normal Data por J. García - Verdugo
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W2 Non Normal DataJavier Garcia - Verdugo Sanchez - Six Sigma Training - W2 Non Normal Data
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W2 Non Normal Data

Similar a Data structure - Graph

graph.pptx por
graph.pptxgraph.pptx
graph.pptxDEEPAK948083
10 vistas34 diapositivas
09_DS_MCA_Graphs.pdf por
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdfPrasanna David
10 vistas69 diapositivas
Graphs por
GraphsGraphs
Graphsamudha arul
175 vistas45 diapositivas
Graph-theory.ppt por
Graph-theory.pptGraph-theory.ppt
Graph-theory.pptAlpaSinghRajput1
17 vistas32 diapositivas
Graph.ppt por
Graph.pptGraph.ppt
Graph.pptAlpaSinghRajput1
3 vistas32 diapositivas
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs por
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsFallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsSnehilKeshari
374 vistas104 diapositivas

Similar a Data structure - Graph(20)

Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs por SnehilKeshari
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphsFallsem2015 16 cp4194-13-oct-2015_rm01_graphs
Fallsem2015 16 cp4194-13-oct-2015_rm01_graphs
SnehilKeshari374 vistas
Dsa.PPT por boltkat
Dsa.PPTDsa.PPT
Dsa.PPT
boltkat12 vistas
Graph representation por DEEPIKA T
Graph representationGraph representation
Graph representation
DEEPIKA T45 vistas
Elements of Graph Theory for IS.pptx por miki304759
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
miki30475954 vistas
Graph terminologies & special type graphs por Nabeel Ahsen
Graph terminologies & special type graphsGraph terminologies & special type graphs
Graph terminologies & special type graphs
Nabeel Ahsen6.4K vistas
Ass. (3)graph d.m por Syed Umair
Ass. (3)graph d.mAss. (3)graph d.m
Ass. (3)graph d.m
Syed Umair566 vistas
Graph in Discrete mathemaetics.pptx por ujjwalmatoliya
Graph in Discrete mathemaetics.pptxGraph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptx
ujjwalmatoliya11 vistas
Matrix representation of graph por Rounak Biswas
Matrix representation of graphMatrix representation of graph
Matrix representation of graph
Rounak Biswas3.2K vistas

Más de Madhu Bala

Internet of Things (IoT) por
Internet of Things (IoT)Internet of Things (IoT)
Internet of Things (IoT)Madhu Bala
231 vistas28 diapositivas
Digital logic por
Digital logicDigital logic
Digital logicMadhu Bala
169 vistas25 diapositivas
Operating system por
Operating systemOperating system
Operating systemMadhu Bala
6.4K vistas15 diapositivas
Greedy Algorithm - Knapsack Problem por
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
24.5K vistas15 diapositivas
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST) por
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)Madhu Bala
1.1K vistas27 diapositivas
Divide and conquer - Quick sort por
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
5.9K vistas19 diapositivas

Más de Madhu Bala(10)

Internet of Things (IoT) por Madhu Bala
Internet of Things (IoT)Internet of Things (IoT)
Internet of Things (IoT)
Madhu Bala231 vistas
Digital logic por Madhu Bala
Digital logicDigital logic
Digital logic
Madhu Bala169 vistas
Operating system por Madhu Bala
Operating systemOperating system
Operating system
Madhu Bala6.4K vistas
Greedy Algorithm - Knapsack Problem por Madhu Bala
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala24.5K vistas
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST) por Madhu Bala
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
GRAPH APPLICATION - MINIMUM SPANNING TREE (MST)
Madhu Bala1.1K vistas
Divide and conquer - Quick sort por Madhu Bala
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala5.9K vistas
GPRS Technology por Madhu Bala
GPRS TechnologyGPRS Technology
GPRS Technology
Madhu Bala984 vistas
Algorithm - Introduction por Madhu Bala
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
Madhu Bala2.4K vistas
4G technology por Madhu Bala
4G technology4G technology
4G technology
Madhu Bala225 vistas
Smoothing Filters in Spatial Domain por Madhu Bala
Smoothing Filters in Spatial DomainSmoothing Filters in Spatial Domain
Smoothing Filters in Spatial Domain
Madhu Bala28.6K vistas

Último

REPRESENTATION - GAUNTLET.pptx por
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
107 vistas26 diapositivas
Women from Hackney’s History: Stoke Newington by Sue Doe por
Women from Hackney’s History: Stoke Newington by Sue DoeWomen from Hackney’s History: Stoke Newington by Sue Doe
Women from Hackney’s History: Stoke Newington by Sue DoeHistory of Stoke Newington
157 vistas21 diapositivas
Structure and Functions of Cell.pdf por
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
701 vistas10 diapositivas
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx por
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxDebapriya Chakraborty
684 vistas81 diapositivas
The basics - information, data, technology and systems.pdf por
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdfJonathanCovena1
126 vistas1 diapositiva
When Sex Gets Complicated: Porn, Affairs, & Cybersex por
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & CybersexMarlene Maheu
73 vistas73 diapositivas

Último(20)

REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood107 vistas
Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan701 vistas
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1126 vistas
When Sex Gets Complicated: Porn, Affairs, & Cybersex por Marlene Maheu
When Sex Gets Complicated: Porn, Affairs, & CybersexWhen Sex Gets Complicated: Porn, Affairs, & Cybersex
When Sex Gets Complicated: Porn, Affairs, & Cybersex
Marlene Maheu73 vistas
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx por Ms. Pooja Bhandare
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptxPharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx
Pharmaceutical Inorganic chemistry UNIT-V Radiopharmaceutical.pptx
Ms. Pooja Bhandare93 vistas
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... por Ms. Pooja Bhandare
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Ms. Pooja Bhandare109 vistas
Ch. 8 Political Party and Party System.pptx por Rommel Regala
Ch. 8 Political Party and Party System.pptxCh. 8 Political Party and Party System.pptx
Ch. 8 Political Party and Party System.pptx
Rommel Regala53 vistas
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively por PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 598 vistas
Create a Structure in VBNet.pptx por Breach_P
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
Breach_P75 vistas
Monthly Information Session for MV Asterix (November) por Esquimalt MFRC
Monthly Information Session for MV Asterix (November)Monthly Information Session for MV Asterix (November)
Monthly Information Session for MV Asterix (November)
Esquimalt MFRC58 vistas
On Killing a Tree.pptx por AncyTEnglish
On Killing a Tree.pptxOn Killing a Tree.pptx
On Killing a Tree.pptx
AncyTEnglish66 vistas
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov111 vistas
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar177 vistas

Data structure - Graph

  • 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

Notas del editor

  1. Inverse adjacenecy list – determine in-degree fast