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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular graph
Complete graph
Path
Cycle
Bipartitie graph
Euler graph
Hamilton graph
Planar graph
Tree and forest
Donglei Du (UNB) Social Network Analysis 12 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Important graphs
Regular 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Graph-theoretic concepts
Density
Degree indegree and outdegree
Path and cycles
Distance diameter
Components
Clustering coefficient
Donglei Du (UNB) Social Network Analysis 26 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 5 4 3)
Cycle A path with the same start andend node (eg 1 2 5)
Donglei Du (UNB) Social Network Analysis 31 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Walk and Path
1
2
3
4
5
6
Walk a walk is a sequence of nodes inwhich each node is adjacent to thenext one
A walk can intersect itself and passthrough the same link repeatedlyEach time a link is crossed it iscounted separatelyOne walk on the graph1 2 5 1 2 3 4In a directed network the walk canfollow only the direction of an arrow
A path is a walk without passingthrough the same link more than once(eg 1 2 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs the distance fromone node A to another B is generallydifferent from that from B to A
Donglei Du (UNB) Social Network Analysis 32 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Distance
1
2
3
4
5
6
The distance dij (shortest pathgeodesic path) between two nodes iand j is the number of edges alongthe shortest path connecting them
The Distance between every pair ofnodes are
1 2 3 4 5 6
1 0 1 2 2 1 32 1 0 1 2 1 33 2 1 0 1 2 24 2 2 1 0 1 15 1 1 2 1 0 26 3 3 2 1 2 0
For directed graphs 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for example that the number of triangles in anundirected graph G is exactly the trace of A33
Donglei Du (UNB) Social Network Analysis 34 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Number of walks of length k
If A is the adjacency matrix of the directed or undirected graphG then the matrix Ak (ie the matrix product of k copies ofA) has an interesting interpretation
the entry in row i and column j gives the number of (directed orundirected) walks of length k from vertex i to vertex j
This implies for 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
undirected graph
Figure A graph with three connectedcomponents
A graph is connected if there is apath between every pair of nodesA connected component is asubgraph in which any two nodesare connected to each other bypaths and which is connected tono additional nodes in the 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
directed graph
Figure 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Connectivity and connected components for
directed graph
Figure A graph with three strongly connectedcomponents
A directed graph is strongly connectedif 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Clustering coefficient
BE BE
A
CD
For any given node A and two randomly selected nodes B and C
CC(A) = P(B isin N(C)|BC isin N(A))
= P(two randomly selected friends of A are friends)
= P(fraction of pairs of Arsquos friends that are linked 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 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
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton0)ocgs[i]state=false
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
Duncan Watts - The Myth of Common Sense
httpwwwyoutubecomwatchfeature=player_
detailpageampv=D9XF0QOzWM0
Donglei Du (UNB) Social Network Analysis 39 1
var ocgs=hostgetOCGs(hostpageNum)for(var i=0iltocgslengthi++)if(ocgs[i]name==MediaPlayButton1)ocgs[i]state=false
References I
Donglei Du (UNB) Social Network Analysis 40 1
References I
Donglei Du (UNB) Social Network Analysis 40 1