Social Network Analysis Lecture 2-Introduction Graph Theory
Transcript of Social Network Analysis Lecture 2-Introduction Graph Theory
![Page 1: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/1.jpg)
Social Network Analysis
Lecture 2-Introduction Graph Theory
Donglei Du(dduunbca)
Faculty of Business Administration University of New Brunswick NB Canada FrederictonE3B 9Y2
Donglei Du (UNB) Social Network Analysis 1 1
Table of contents
Donglei Du (UNB) Social Network Analysis 2 1
Layout
Donglei Du (UNB) Social Network Analysis 3 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 2: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/2.jpg)
Table of contents
Donglei Du (UNB) Social Network Analysis 2 1
Layout
Donglei Du (UNB) Social Network Analysis 3 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 3: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/3.jpg)
Layout
Donglei Du (UNB) Social Network Analysis 3 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 4: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/4.jpg)
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 5: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/5.jpg)
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 6: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/6.jpg)
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 7: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/7.jpg)
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 8: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/8.jpg)
What is Graph theory
Graph theory is the study of graphs which are mathematicalrepresentation of a network used to model pairwise relationsbetween objects
A graph consists of a set of rdquoverticesrdquo or rdquonodesrdquo with certainpairs of these nodes connected by rdquoedgesrdquo (undirected) orrdquoarcsrdquo (directed)
A graph may be undirected meaning that there is no distinctionbetween the two vertices associated with each edge or directedmeaning that its arcs may be directed from one vertex toanother
This is an extremely brief introduction of graph theory
Donglei Du (UNB) Social Network Analysis 4 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 9: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/9.jpg)
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 10: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/10.jpg)
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 11: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/11.jpg)
The Seven Bridges of Konigsberg
Q Is there a Eulerian trail through thecity that would cross each bridge onceand only once (The second(undirected) graph represents thebridge network)
A an (connected) undirected graphhas an Eulerian trail if and only if atmost two vertices have odd degree
Leonhard Euler (15 April 1707-18September 1783 SwissMathematician) in 1735 laid thefoundations of graph theory andprefigured the idea of topology bystudying this problem
Donglei Du (UNB) Social Network Analysis 5 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 12: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/12.jpg)
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 13: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/13.jpg)
The Erdos coauthor network and Erdos number
Paul Erdos (26 March 191320September 1996 Hungarianmathematician) one of the mostprolific publishers of papers inmathematical history comparable onlywith Leonhard Euler Erdos publishedmore papers mostly in collaborationwith other mathematicians whileEuler published more pages mostly byhimself
Donglei Du (UNB) Social Network Analysis 6 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 14: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/14.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 15: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/15.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261
Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 16: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/16.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239
Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 17: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/17.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782
Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 18: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/18.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 19: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/19.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 20: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/20.jpg)
My Erdos Number 3
Paul Erdos (0) and Prasad Tetali (1) Representations of integers as thesum of k terms Random Structures Algorithms 1(3) (1990) 245-261Prasad Tetali (1) Juan C Vera (2) Eric Vigoda and Linji Yang Phasetransition for the mixing time of the Glauber dynamics for coloringregular trees Annals of Applied Probability 22(6) (2012) 2210-2239Qiaming Han Donglei Du (3) Juan C Vera (2) and Luis F ZuluagImproved bounds for the symmetric rendezvous search problem on theline Operations Research 56(3) (2008) 772-782Find your own Erdos Number
herehttpwwwamsorgmathscinetcollaborationDistancehtml
If you want to know more about Erdos Numbertry herehttpwwwoaklandeduenpcompute
Donglei Du (UNB) Social Network Analysis 7 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 21: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/21.jpg)
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 22: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/22.jpg)
Six Degrees of Kevin Bacon
Kevin Norwood Bacon (July 8 1958-) is an American actor and musician
Donglei Du (UNB) Social Network Analysis 8 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 23: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/23.jpg)
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 24: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/24.jpg)
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 25: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/25.jpg)
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship network
Directed networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 26: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/26.jpg)
Types of graphs
Undirected vs directed
Undirected networks coauthorship network actor network KonigsbergBridges Network Facebook friendship networkDirected networks URLs on the www phone calls Retweet network
Donglei Du (UNB) Social Network Analysis 9 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 27: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/27.jpg)
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 28: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/28.jpg)
Types of graphs
Simple vs multigraph lops or multiedges
Donglei Du (UNB) Social Network Analysis 10 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 29: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/29.jpg)
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 30: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/30.jpg)
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 31: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/31.jpg)
Types of graphs
Unweighted vs weighted
S
N
H
M
F
W
Fredericton
Hampton
Moncton
St Stephen
Woodstock
New Bandon
807010050 60
85
140
110
80
65
150
105
7875
70
Mobile phone calls Collaboration network
Donglei Du (UNB) Social Network Analysis 11 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 32: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/32.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 33: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/33.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 34: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/34.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 35: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/35.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 36: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/36.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 37: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/37.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 38: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/38.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 39: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/39.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 40: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/40.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 41: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/41.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 42: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/42.jpg)
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 43: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/43.jpg)
Layout
Donglei Du (UNB) Social Network Analysis 13 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 44: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/44.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 45: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/45.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 46: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/46.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrix
Edge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 47: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/47.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge list
Adjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 48: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/48.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency list
Laplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 49: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/49.jpg)
Representation of graphs using different data
structure (Hi Computer Science guys)
Graph can be represented in many different ways for differentpurpose
Adjacency matrixEdge listAdjacency listLaplace matrix
Donglei Du (UNB) Social Network Analysis 14 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 50: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/50.jpg)
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 51: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/51.jpg)
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 52: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/52.jpg)
Adjacency matrix undirected graph
1
2
3
4
5
6
Adjacency matrix Aij = 1 iffthere is a link between i and j
1 2 3 4 5 61 0 1 0 0 1 02 1 0 1 0 1 03 0 1 0 1 0 04 0 0 1 0 1 15 1 1 0 1 0 06 0 0 0 1 0 0
The adjacency is symmetric forundirected graph
Donglei Du (UNB) Social Network Analysis 15 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 53: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/53.jpg)
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_ult-matrix(
c(0 1 0 0 1 0
1 0 1 0 1 0
0 1 0 1 0 0
0 0 1 0 1 1
1 1 0 1 0 0
0 0 0 1 0 0) the data elements
nrow=6 number of rows
ncol=6 number of columns
byrow = TRUE) fill matrix by rows
g_adj_u lt- graphadjacency(adjm_u mode=undirected)
tkplot(g_adj_u)
Donglei Du (UNB) Social Network Analysis 16 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 54: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/54.jpg)
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 55: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/55.jpg)
Adjacency matrix directed graph
1
2
3
4
5
Adjacency matrix Aij = 1 iffthere is a link from j to i
1 2 3 4 51 0 0 0 0 02 1 0 0 1 03 0 1 0 1 04 0 1 0 0 15 0 1 0 0 0
Note the direction of the edgeruns from the second index to thefirst counter-intuitive butconvenient mathematically
Donglei Du (UNB) Social Network Analysis 17 1
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 56: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/56.jpg)
R code based on package igraph generate graph
from adjacency matrix
library(igraph)
Generate graph object from adjacency matrix
adjm_dlt-matrix(
c(0 1 0 0 0
0 0 1 1 1
0 0 0 0 0
0 1 1 0 0
0 0 0 1 0) the data elements
nrow=5 number of rows
ncol=5 number of columns
byrow = TRUE) fill matrix by rows
g_adj_d lt- graphadjacency(adjm_d mode=directed)
tkplot(g_adj_d)
Donglei Du (UNB) Social Network Analysis 18 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 57: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/57.jpg)
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 58: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/58.jpg)
Edge list undirected graph
1
2
3
4
5
6
Edge list
(12)(15)(23)(25)(34)(45)(46)
Donglei Du (UNB) Social Network Analysis 19 1
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 59: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/59.jpg)
R code based on package igraph generate
undirected graph from edge list
library(igraph)
Generate graph object from edge list
el_u lt- matrix( c(1 2 1 5 2325344546) nc=2 byrow=TRUE)
g_el_u lt- graphedgelist(el_udirected=FALSE)
tkplot(g_el_u)
Donglei Du (UNB) Social Network Analysis 20 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 60: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/60.jpg)
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 61: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/61.jpg)
Edge list directed graph
1
2
3
4
5
Edge list12232442254354
Donglei Du (UNB) Social Network Analysis 21 1
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 62: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/62.jpg)
R code based on package igraph generate directed
graph from edge list
library(igraph)
Generate graph object from edge list
el_d lt- matrix( c(1 2 2 3 2442254354) nc=2 byrow=TRUE)
g_el_d lt- graphedgelist(el_ddirected=TRUE)
tkplot(g_el_d)
Donglei Du (UNB) Social Network Analysis 22 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 63: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/63.jpg)
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 64: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/64.jpg)
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 65: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/65.jpg)
Adjacency list undirected graph
1
2
3
4
5
6
Adjacency list
node neighbor1 2 52 1 3 53 2 44 3 5 65 1 2 46 4
Easier to work with if network is largeand parse and quick in retrieving allneighbors for a node
Donglei Du (UNB) Social Network Analysis 23 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 66: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/66.jpg)
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 67: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/67.jpg)
Adjacency list directed graph
1
2
3
4
5
Adjacency list
node inneighbor outneighbor1 22 14 3453 244 25 235 2 4
Donglei Du (UNB) Social Network Analysis 24 1
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 68: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/68.jpg)
Layout
Donglei Du (UNB) Social Network Analysis 25 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 69: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/69.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 70: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/70.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 71: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/71.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 72: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/72.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 73: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/73.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 74: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/74.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 75: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/75.jpg)
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 76: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/76.jpg)
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 77: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/77.jpg)
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 78: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/78.jpg)
Degree for undirected graph
1
2
3
4
5
6
Degree of any node i the number ofnodes adjacent to i It can becalculated from the three differentrepresentations discussed earlier
Every loop adds two degrees to anode
node degree1 22 33 24 35 36 1
Donglei Du (UNB) Social Network Analysis 27 1
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 79: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/79.jpg)
R code based on package igraph degree
degree(g_adj_u)
Donglei Du (UNB) Social Network Analysis 28 1
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 80: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/80.jpg)
Indegree and outdegree for directed graph
1
2
3
4
5
Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 81: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/81.jpg)
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to i
Outdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 82: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/82.jpg)
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 83: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/83.jpg)
Indegree and outdegree for directed graph
1
2
3
4
5Indegree of any node i the number ofnodes destined to iOutdegree of any node i the numberof nodes originated at i
Every loop adds one degree to eachof the indegree and outdegree of anodenode indegree outdegree1 0 12 2 33 2 04 2 25 1 1
Donglei Du (UNB) Social Network Analysis 29 1
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 84: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/84.jpg)
R code based on package igraph degree
degree(g_adj_d mode=in)
degree(g_adj_d mode=out)
Donglei Du (UNB) Social Network Analysis 30 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 85: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/85.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 86: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/86.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 87: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/87.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separately
One walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 88: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/88.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4
In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 89: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/89.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 90: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/90.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 91: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/91.jpg)
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 92: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/92.jpg)
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 93: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/93.jpg)
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 94: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/94.jpg)
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 95: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/95.jpg)
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 96: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/96.jpg)
R code based on package igraph distance
shortestpaths(g_adj_u)
Donglei Du (UNB) Social Network Analysis 33 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 97: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/97.jpg)
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 98: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/98.jpg)
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 99: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/99.jpg)
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 100: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/100.jpg)
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 101: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/101.jpg)
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 102: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/102.jpg)
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodes
A connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 103: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/103.jpg)
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraph
Largest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 104: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/104.jpg)
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponent
Bridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 105: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/105.jpg)
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the originalgraphLargest Component GiantComponentBridge an edge whose deletionincreases the number ofconnected components
Donglei Du (UNB) Social Network Analysis 35 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 106: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/106.jpg)
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 107: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/107.jpg)
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versa
A directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 108: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/108.jpg)
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirections
A strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 109: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/109.jpg)
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif there is a path from any node toeach other node and vice versaA directed graph is weakly connectedif it is connected by ignoring the edgedirectionsA strongly connected component of adirected graph G is a subgraph that isstrongly connected and is maximalwith this property no additional edgesor vertices from G can be included inthe subgraph without breaking itsproperty of being strongly directed
Donglei Du (UNB) Social Network Analysis 36 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 110: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/110.jpg)
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 111: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/111.jpg)
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 112: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/112.jpg)
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked to each other)
For example in the Figure above
node CCA 1B 13C 13D 0E 0
Donglei Du (UNB) Social Network Analysis 37 1
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 113: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/113.jpg)
R code based on package igraph Clustering
coefficient
First generate the graph from edge list
el_cc lt- matrix( c(A B AC B
C BEDECD) nc=2 byrow=TRUE)
g_el_cc lt- graphedgelist(el_ccdirected=FALSE)
Then calculate CC
transitivity(g_el_cc type=localundirected)
Donglei Du (UNB) Social Network Analysis 38 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 114: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/114.jpg)
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 115: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/115.jpg)
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
![Page 116: Social Network Analysis Lecture 2-Introduction Graph Theory](https://reader035.fdocuments.us/reader035/viewer/2022081722/58a30b261a28ab3a468b5f0e/html5/thumbnails/116.jpg)
References I
Donglei Du (UNB) Social Network Analysis 40 1
- Graph theory
-
- What is Graph theory
- Graphs in real life
- Types of graphs
-
- Graph representation
- Graph theory concepts
-