Find out the difference(s)?
Shape 1 Shape 2
Find out the difference(s)?
Graph G1 Graph G2
Connectivity in graphs
Jean Cousty MorphoGraph and Imagery
2011
Outline of the lecture
1 Path
2 Connectivity
3 Algorithms
4 Degrees
Path
Path
Definition
Let G = (E,Γ) be a graph, and let x and y be two vertices in E A path fromx toy (inG) is a sequenceπ = (x0, . . . ,x`)of vertices in E such that
∀i∈ {1, . . . , `}, xi∈Γ(xi−1) x0=x and x`=y
Ifπ= (x0, . . . ,x`) is a path, `is called itslength
2
3
4 1
Exemple
π= (1,2,3)is a path
of length 2
Path
Path
Definition
Let G = (E,Γ) be a graph, and let x and y be two vertices in E A path fromx toy (inG) is a sequenceπ = (x0, . . . ,x`)of vertices in E such that
∀i∈ {1, . . . , `}, xi∈Γ(xi−1) x0=x and x`=y
Ifπ= (x0, . . . ,x`) is a path, `is called itslength
2
3 1
Exemple
π= (1,2,3)is a path
of length 2
Path
Path
Definition
Let G = (E,Γ) be a graph, and let x and y be two vertices in E A path fromx toy (inG) is a sequenceπ = (x0, . . . ,x`)of vertices in E such that
∀i∈ {1, . . . , `}, xi∈Γ(xi−1) x0=x and x`=y
Ifπ = (x0, . . . ,x`) is a path, `is called itslength
2
3
4 1
Exemple
π= (1,2,3)is a path of length 2
Path
Some remarkable paths
A path of length 0 is called a trivial path
A non-trivial pathπ= (x0, . . . ,x`) is called a circuit ifx0=x` A pathπ= (x0, . . . ,x`) is calledelementaryif any two of its vertices are distinct (except possiblyx0 andx`): ∀i,j ∈ {0, . . . , `}, i 6=j =⇒ xi 6=xj (where{i,j} 6={0, `})
2
3
4 1
Exemple
(3)is a trivial path
(1,2,3,1)is a circuit
that is elementary
(1,3,1,2,3,1)is a circuit that is not elementary
Path
Some remarkable paths
A path of length 0 is called a trivial path
A non-trivial path π= (x0, . . . ,x`) is called a circuit ifx0=x`
A pathπ= (x0, . . . ,x`) is calledelementaryif any two of its vertices are distinct (except possiblyx0 andx`): ∀i,j ∈ {0, . . . , `}, i 6=j =⇒ xi 6=xj (where{i,j} 6={0, `})
2
3
4 1
Exemple
(3)is a trivial path (1,2,3,1)is a circuit
that is elementary
(1,3,1,2,3,1)is a circuit that is not elementary
Path
Some remarkable paths
A path of length 0 is called a trivial path
A non-trivial path π= (x0, . . . ,x`) is called a circuit ifx0=x` A path π= (x0, . . . ,x`) is calledelementaryif any two of its vertices are distinct (except possibly x0 andx`): ∀i,j ∈ {0, . . . , `}, i 6=j =⇒ xi 6=xj (where{i,j} 6={0, `})
2
3
4 1
Exemple
(3)is a trivial path
(1,2,3,1)is a circuit that is elementary
(1,3,1,2,3,1)is a circuit that is not elementary
Path
Some remarkable paths
A path of length 0 is called a trivial path
A non-trivial path π= (x0, . . . ,x`) is called a circuit ifx0=x` A path π= (x0, . . . ,x`) is calledelementaryif any two of its vertices are distinct (except possibly x0 andx`): ∀i,j ∈ {0, . . . , `}, i 6=j =⇒ xi 6=xj (where{i,j} 6={0, `})
2
3
4 1
Exemple
(3)is a trivial path
(1,2,3,1)is a circuit that is elementary
(1,3,1,2,3,1)is a circuit that is not elementary
Path
Basic properties
Property
Any path π from x to y contains an elementary path from x to y
The length of an elementary circuit is less than n (where n=|E|) The length of an elementary path which is not a circuit is less than n−1
Path
Basic properties
Property
Any path π from x to y contains an elementary path from x to y The length of an elementary circuit is less than n (where n =|E|)
The length of an elementary path which is not a circuit is less than n−1
Path
Basic properties
Property
Any path π from x to y contains an elementary path from x to y The length of an elementary circuit is less than n (where n =|E|) The length of an elementary path which is not a circuit is less than n−1
Path
Undirected paths and cycles
Definition
Let Gs = (E,Γs) be the symmetric closure of G
Any path in Gs is called anundirected path (in G)
Acycle (in G)is a circuit in Gs that does not pass twice by the same edge
Remark. Ifπ= (x0, . . . ,x`) is an undirected path,
thenπ0 = (x`, . . . ,x0) is an undirected path (since (E,Γs) is a symmetric graph, which implies thatxi ∈Γs(xi−1)⇔xi−1∈Γs(xi))
Path
Undirected paths and cycles
Definition
Let Gs = (E,Γs) be the symmetric closure of G Any path in Gs is called anundirected path (in G)
Acycle (in G)is a circuit in Gs that does not pass twice by the same edge
Remark. Ifπ= (x0, . . . ,x`) is an undirected path,
thenπ0 = (x`, . . . ,x0) is an undirected path (since (E,Γs) is a symmetric graph, which implies thatxi ∈Γs(xi−1)⇔xi−1∈Γs(xi))
Path
Undirected paths and cycles
Definition
Let Gs = (E,Γs) be the symmetric closure of G Any path in Gs is called anundirected path (in G)
A cycle (in G)is a circuit in Gs that does not pass twice by the same edge
Remark. Ifπ= (x0, . . . ,x`) is an undirected path,
thenπ0 = (x`, . . . ,x0) is an undirected path (since (E,Γs) is a symmetric graph, which implies thatxi ∈Γs(xi−1)⇔xi−1∈Γs(xi))
Path
Undirected paths and cycles
Definition
Let Gs = (E,Γs) be the symmetric closure of G Any path in Gs is called anundirected path (in G)
A cycle (in G)is a circuit in Gs that does not pass twice by the same edge
Remark. Ifπ= (x0, . . . ,x`) is an undirected path,
thenπ0 = (x`, . . . ,x0) is an undirected path (since (E,Γs) is a symmetric graph, which implies thatxi ∈Γs(xi−1)⇔xi−1 ∈Γs(xi))
Path
Illustration: path and undirected path, circuit and cycles
2
3
4 1
Exemple
(1,2,1)is not a path (1,2,3,1,2,4)is a path (4,2,1)is an undirected path (1,3,2,1)is not a circuit (1,3,1)is not a cycle
(1,2,3)is a path (4,2,1)is not a path (1,2,3,1)is a circuit (1,3,2,1)is a cycle
Connectivity
Connected component
Definition
Let x ∈E . The connected component of G containingx is the subset Cx of E defined by:
Cx ={y ∈E |there exists an undirected path from x to y}
Exemple
0 1
0
1 01
0 1 0 1
0 1 0000
1111 0 01 01
1 00
11
00 11
00 11 0 1
00 11 00 11
1 2
3
4
6 7 8
5 C1 ={1,2,3,4}=C2 =
C3 =C4 C5 ={5}
C6 =C7=C8 ={6,7,8}
Connectivity
Connected component
Definition
Let x ∈E . The connected component of G containingx is the subset Cx of E defined by:
Cx ={y ∈E |there exists an undirected path from x to y}
Exemple
0 1
0 1
0 1 0 1 0 1
0 1 0000
1111 0 01 01
1 00
11
00 11
00 11 0 1
00 11 00 11
1 2
3
4
6 7 8
5 C1 ={1,2,3,4}=C2 =
C3 =C4 C5 ={5}
C6 =C7 =C8={6,7,8}
Connectivity
Connected component as equivalence classes
Property
1 ∀x∈E , x ∈Cx (reflexivity)
2 ∀x,y ∈E , y ∈Cx =⇒ x ∈Cy (symmetry)
3 ∀x,y,z ∈E , [y ∈Cx and z ∈Cy] =⇒ z ∈Cx (transitivity)
Proof.
1 ∀x∈E, (x) is a (trivial) undirected path, thusx ∈Cx
2 y ∈Cx =⇒ ∃an undirected pathπ = (x0, . . . , ,x`) fromx toy
=⇒ π0 = (x`, . . . ,x0) is an undirected path fromy tox
=⇒ x ∈Cy
3 [y ∈Cx andz ∈Cy] =⇒ [∃ an undirected pathπ = (x0, . . . ,x`) from x to y and∃an undirected path π0= (y0, . . . ,ym) fromy to z] =⇒ π00= (x0, . . . ,x`,y1, . . . ,ym) is an undirected path
Connectivity
Strongly connected component
Definition
Let x ∈E . The strongly connected component (ofG) containing x is the subset Cx0 of E defined by
Cx0 ={y ∈E | ∃a path from x to y and ∃a path from y to x}
Exemple
0 1
0
1 01
0 1 0 1
0 1 0000
1111 0 01 01
1 00
11
00 11
00 11 0 1
00 11 00 11
1 2
3
4
6 7 8
5 C10 ={1,2,3}=C20 =C30
C40 ={4} ; C50 ={5} C60 ={6} ; C70 ={7} C80 ={8}
Connectivity
Strongly connected component
Definition
Let x ∈E . The strongly connected component (ofG) containing x is the subset Cx0 of E defined by
Cx0 ={y ∈E | ∃a path from x to y and ∃a path from y to x}
Exemple
0 1
0 1 0 1
0 1 0000
1111 0 01 01
1 00
11
0 1
00 11 00 11
1 2
3
7 8
5 C10 ={1,2,3}=C20 =C30
C40 ={4} ; C50 ={5}
C60 ={6} ; C70 ={7}
C0 ={8}
Connectivity
Strongly connected components as equivalence classes?
Exercise. Are the strongly connected components of a graphs equivalence classes? Proof or counter-example?
Algorithms
Connected and strongly connected components computation
Method
We will first study a characterization of connected components and of strongly connected components based on morphological dilation This will allow us to propose efficient algorithm to compute them
Algorithms
Iterated operators
Definition
Let γ be an operator and i ∈N
We denote by γi the operator defined by
1 γi=γγi−1
2 γ0=Id (i.e. ∀X ⊆E, γ0(X) =X )
Exemple (iterated dilation)
1 δ0Γ(X) =X
2 δ1Γ(X) =δΓ(δ0Γ(X)) =δΓ(X)
3 δ2Γ(X) =δΓ(δ1Γ(X)) =δΓ(δΓ(X))
4 δ3Γ(X) =δΓ(δ2Γ(X)) =δΓ(δΓ(δΓ(X)))
5 . . .
6 δiΓ(X) =δΓ(δiΓ−1(X)) =δΓ(. . . δΓ(X). . .)
Algorithms
Iterated operators
Definition
Let γ be an operator and i ∈N
We denote by γi the operator defined by
1 γi=γγi−1
2 γ0=Id (i.e. ∀X ⊆E, γ0(X) =X )
Exemple (iterated dilation)
1 δ0Γ(X) =X
2 δ1Γ(X) =δΓ(δ0Γ(X)) =δΓ(X)
3 δ2Γ(X) =δΓ(δ1Γ(X)) =δΓ(δΓ(X))
4 δ3Γ(X) =δΓ(δ2Γ(X)) =δΓ(δΓ(δΓ(X)))
5 . . .
Algorithms
Illustration: iterated dilation
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2} δ2Γ(X) ={3,4}
Algorithms
Illustration: iterated dilation
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2}
δ2Γ(X) ={3,4}
Algorithms
Illustration: iterated dilation
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2}
δ2Γ(X) ={3,4}
Algorithms
Iterated dilation and paths of given length
Property
Let x ∈E and i ∈N
The two following equalities hold true
δiΓ({x}) ={y ∈E | ∃a path from x to y of length i}
δiΓ−1({x}) ={y∈E | ∃a path from y to x of length i}
Definition
We define for any X ⊆E and any p∈N δˆpΓ(X) =∪{δΓi(X)|i∈ {0, . . . ,p}}
The setδˆΓp(X) is called the pre-closure ofX of rankp
Algorithms
Iterated dilation and paths of given length
Property
Let x ∈E and i ∈N
The two following equalities hold true
δiΓ({x}) ={y ∈E | ∃a path from x to y of length i}
δiΓ−1({x}) ={y∈E | ∃a path from y to x of length i}
Definition
We define for any X ⊆E and any p∈N δˆpΓ(X) =∪{δiΓ(X)|i∈ {0, . . . ,p}}
The setδˆΓp(X) is called the pre-closure ofX of rankp
Algorithms
Iterated dilation and paths of given length
Property
Let x ∈E and i ∈N
The two following equalities hold true
δiΓ({x}) ={y ∈E | ∃a path from x to y of length i}
δiΓ−1({x}) ={y∈E | ∃a path from y to x of length i}
Definition
We define for any X ⊆E and any p∈N δˆpΓ(X) =∪{δiΓ(X)|i∈ {0, . . . ,p}}
The set δˆΓp(X) is called the pre-closure ofX of rankp
Algorithms
Transitive closure and paths
Corollary
Let x ∈E
The two following equalities hold true
δˆpΓ({x}) ={y∈E | ∃a path from x to y of length ≤p}
δpΓˆ−1({x}) ={y∈E | ∃a path from y to x of length ≤p}
Definition
Let x ∈E , the (transitive) closure of {x} is the set δˆ∞Γ ({x}) ={y ∈E | ∃a path from x to y}
Exercise. Prove that ˆδΓ∞({x}) =δΓn−1ˆ ({x}) (wheren=|E|)
Algorithms
Transitive closure and paths
Corollary
Let x ∈E
The two following equalities hold true
δˆpΓ({x}) ={y∈E | ∃a path from x to y of length ≤p}
δpΓˆ−1({x}) ={y∈E | ∃a path from y to x of length ≤p}
Definition
Let x ∈E , the (transitive) closure of {x} is the set δˆ∞Γ ({x}) ={y ∈E | ∃a path from x to y}
Exercise. Prove that ˆδΓ∞({x}) =δΓn−1ˆ ({x}) (wheren=|E|)
Algorithms
Transitive closure and paths
Corollary
Let x ∈E
The two following equalities hold true
δˆpΓ({x}) ={y∈E | ∃a path from x to y of length ≤p}
δpΓˆ−1({x}) ={y∈E | ∃a path from y to x of length ≤p}
Definition
Let x ∈E , the (transitive) closure of {x} is the set δˆ∞Γ ({x}) ={y ∈E | ∃a path from x to y}
Exercise. Prove that ˆδΓ∞({x}) =δΓn−1ˆ ({x}) (where n=|E|)
Algorithms
Illustration: transitive closure
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2} δ2Γ(X) ={3,4}
X = ˆδ0Γ(X) ={1}
δˆΓ1(X) ={1,2}
δˆΓ2(X) ={1,2,3,4}= ˆδΓ7(X)
Algorithms
Illustration: transitive closure
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2}
δ2Γ(X) ={3,4}
X = ˆδ0Γ(X) ={1}
δˆΓ1(X) ={1,2}
δˆΓ2(X) ={1,2,3,4}= ˆδΓ7(X)
Algorithms
Illustration: transitive closure
1 2
3
4
6 7 8
5
Exemple
X =δ0Γ(X) ={1}
δ1Γ(X) ={2}
δ2(X) ={3,4}
X = ˆδ0Γ(X) ={1}
δˆΓ1(X) ={1,2}
δˆ2(X) ={1,2,3,4}= ˆδ7(X)
Algorithms
Transitive closure and connected components
Property
Let x ∈E . Let Cx and Cx0 be respectively the connected
components and the strongly connected components containing x
The two following equalities hold true Cx0 =δΓn−1ˆ ({x})∩δΓn−1ˆ−1({x}) Cx =δΓn−1ˆ
s ({x}) =δn−1Γˆ
s ({x})
where n=|E|andΓs is the symmetric closure ofΓ
Important remark
To compute the connected and strongly connected components containingx, it is thus sufficient to compute the transitive closure of{x} for the graphs (E,Γ), (E,Γ−1) and (E,Γs)
Algorithms
Transitive closure and connected components
Property
Let x ∈E . Let Cx and Cx0 be respectively the connected
components and the strongly connected components containing x The two following equalities hold true
Cx0 =δΓn−1ˆ ({x})∩δΓn−1ˆ−1({x}) Cx =δΓn−1ˆ
s ({x}) =δn−1Γˆ
s ({x})
where n=|E|andΓs is the symmetric closure ofΓ
Important remark
To compute the connected and strongly connected components containingx, it is thus sufficient to compute the transitive closure of{x} for the graphs (E,Γ), (E,Γ−1) and (E,Γs)
Algorithms
Transitive closure and connected components
Property
Let x ∈E . Let Cx and Cx0 be respectively the connected
components and the strongly connected components containing x The two following equalities hold true
Cx0 =δΓn−1ˆ ({x})∩δΓn−1ˆ−1({x}) Cx =δΓn−1ˆ
s ({x}) =δn−1Γˆ
s ({x})
where n=|E|andΓs is the symmetric closure ofΓ
Important remark
To compute the connected and strongly connected components containing x, it is thus sufficient to compute the transitive closure of {x} for the graphs (E,Γ), (E,Γ−1) and (E,Γs)
Algorithms
Naive algorithm for the transitive closure of {x }
Algorithm TRANS NAIV ( Data: (E,Γ),x ∈E ;
Results: Z =δΓn−1ˆ ({x}))
X :={x} ;Y :=∅ ;Z :={x} ; For each i from 1 to n−1 do
Y := DIL((E,Γ),X) ; /*Y =δΓi({x}) */
Z :=Z∪Y ; /*Z = ˆδΓi({x}) */
X :=Y;Y :=∅;
Complexity
By using the algorithm DIL studied during practical session # 1 The complexity of TRANS NAIV is
O(n2+nm)(where n=|E|and m=|Γ|)
Algorithms
Naive algorithm for the transitive closure of {x }
Algorithm TRANS NAIV ( Data: (E,Γ),x ∈E ;
Results: Z =δΓn−1ˆ ({x}))
X :={x} ;Y :=∅ ;Z :={x} ; For each i from 1 to n−1 do
Y := DIL((E,Γ),X) ; /*Y =δΓi({x}) */
Z :=Z∪Y ; /*Z = ˆδΓi({x}) */
X :=Y;Y :=∅;
Complexity
By using the algorithm DIL studied during practical session # 1 The complexity of TRANS NAIV is
O(n2+nm)(where n=|E|and m=|Γ|)
Algorithms
Linear-time algorithm for the transitive closure of {x }
Algorithm TRANS ( Data: (E,Γ),x∈E ;
Result: Z =δΓn−1ˆ ({x})) X :={x} ;Y :=∅ ;Z :={x} ;
For eachi from 1 to n−1do While ∃y ∈X do
X :=X \ {y} ; For eachz ∈Γ(y)do
Ifz∈/Z thenY :=Y ∪ {z};Z :=Z ∪ {z};
X :=Y;Y :=∅;
Complexity
If X and Y are represented by LLs and if Z is represented by a BA The time-complexity of TRANS is linear
O(n+m)(where n=|E|and m=|Γ|)
Algorithms
Linear-time algorithm for the transitive closure of {x }
Algorithm TRANS ( Data: (E,Γ),x∈E ;
Result: Z =δΓn−1ˆ ({x})) X :={x} ;Y :=∅ ;Z :={x} ;
For eachi from 1 to n−1do While ∃y ∈X do
X :=X \ {y} ; For eachz ∈Γ(y)do
Ifz∈/Z thenY :=Y ∪ {z};Z :=Z ∪ {z};
X :=Y;Y :=∅;
Complexity
If X and Y are represented by LLs and if Z is represented by a BA The time-complexity of TRANS is linear
O(n+m)(where n=|E|and m=|Γ|)
Algorithms
Linear-time algorithm for the transitive closure of {x }
Algorithm TRANS can be further simplified without changing its complexity:
Algorithm TRANS ( Data: (E,Γ),x∈E ;
Result: Z =δΓn−1ˆ ({x}))
X :={x} ;Z :={x};
While ∃y ∈X do X :=X \ {y};
For eachz ∈Γ(y)do
Ifz∈/Z then X :=X ∪ {z};Z :=Z∪ {z};
Algorithms
Computing the strongly connected component containing x
Algorithm SCC ( Data: (E,Γ),x ∈E ;
Result: Z =Cx0)
X := TRANS((E,Γ),x);
Γ−1 := SYM 1(E,Γ);
Y := TRANS((E,Γ−1), x) Z :=X ∩Y;
Complexity
Using
the linear-time algorithm SYM 1 (first lecture) the linear-time TRANS
The time-complexity of SCC is linear: O(n+m)(where n=|E|and m=|Γ|)
Algorithms
Computing the strongly connected component containing x
Algorithm SCC ( Data: (E,Γ),x ∈E ;
Result: Z =Cx0)
X := TRANS((E,Γ),x);
Γ−1 := SYM 1(E,Γ);
Y := TRANS((E,Γ−1), x) Z :=X ∩Y;
Complexity
Using
the linear-time algorithm SYM 1 (first lecture) the linear-time TRANS
The time-complexity of SCC is linear:
Algorithms
Computing the connected component containing x
Algorithm CC ( Data: (E,Γ),x ∈E ;
Result: Y =Cx)
Γ−1 := SYM 1(E,Γ);
Γs := Γ∪Γ−1 ;
Y := TRANS((E,Γs),x)
Complexity
Using
the linear-time algorithm SYM 1 (first lecture) the linear-time TRANS
The time-complexity of CC is linear: O(n+m)(where n=|E|and m=|Γ|)
Algorithms
Computing the connected component containing x
Algorithm CC ( Data: (E,Γ),x ∈E ;
Result: Y =Cx)
Γ−1 := SYM 1(E,Γ);
Γs := Γ∪Γ−1 ;
Y := TRANS((E,Γs),x)
Complexity
Using
the linear-time algorithm SYM 1 (first lecture) the linear-time TRANS
The time-complexity of CC is linear:
O(n+m)(where n=|E|and m=|Γ|)
Degrees
Application of graphs properties
Problem
In a charity diner, is there always two people having the same number of friends who are present in the diner?
Can we draw in the plan five distinct lines such that any of them has exactly three intersection points with the others?
In order to answer these questions read first the two next slides!
Degrees
Application of graphs properties
Problem
In a charity diner, is there always two people having the same number of friends who are present in the diner?
Can we draw in the plan five distinct lines such that any of them has exactly three intersection points with the others?
In order to answer these questions read first the two next slides!
Degrees
Degree
Let G = (E,Γ) be a graph and letx ∈E
The outer degree of x (for G )is the valued+(x) =|Γ(x)|
The inner degree of x (for G )is the valued−(x) =|Γ−1(x)|
The degree of x (for G )is the valued(x) =d+(x) +d−(x) Let G0 = (E,Γ) be an undirected graph
The degree of x for G0 is the number d(x) of edges that are adjacent to x
Degrees
Degree: exercise
Prove that the two following propositions hold true The sum of the degrees of the vertices of a graph is even
In any graph, there is an even number of vertices whose degree is odd