Title: Final Reminder
1Final Reminder
- Test 3 (CLOSED BOOK TEST)
- Date Saturday 19th October 2002
- Time 1430 - 1545 (1hr 15mins)
- Topics Material from Lec 7-10c
- Venue LT27
- Same procedure as the first 2 tests.
- No lecture this coming Saturday morning, in view
of afternoon test
2Lecture 13
- Graphs II
- (a) Circuits (b) Representation
- Reading Epp Chp 11.2, 11.3
3A. Circuits
- Definitions and examples of Closed Walk, Circuit,
Simple Circuit - A special kind of circuit Euler circuit
- 3. A special kind of simple circuit Hamiltonian
circuit
41. Closed Walk, Circuit, Simple Circuit
- Definition
- Given a graph G(V,E), a closed walk is a walk
that starts and ends at the same vertex i.e. it
is a sequence - v0 e1 v1 e2 v2 en-1 vn-1 en v0
- where n³0 , viÎV, eivi-1 ,viÎE (iÎ1..n-1)
- When obvious, we shorten it the closed walk to
- v0 v1 v2 vn-1 v0
- If all the edges in the closed walk are distinct,
then the closed walk is a circuit. - If all the vertices in the closed walk are
distinct (with exception of the first and last)
then the closed walk is a simple circuit. - The length of the closed walk / circuit / simple
circuit is the number of edges in the closed walk
/ circuit / simple circuit.
51. Closed Walk, Circuit, Simple Circuit
61. Closed Walk, Circuit, Simple Circuit
6
2 1 3 5 6 3 2
1 2 3 6 4 2
5
6 5 1 2 3 6
6
5 3 6 5 1 3 5
7A. Circuits
- Definitions (Closed Walk, Circuit, Simple
Circuit) and Examples - 2. A special kind of circuit
- 2.1 Definition of Euler Circuit
- 2.2 Euler Circuit Theorem and Proof
- 2.3 Examples
- 2.4 (Related) Definition of Euler Path
- 2.5 Euler Path Theorem
- 2.6 Example
- 3. A special kind of simple circuit
- 3.1 Definition of Hamiltonian Circuit
- 3.2 Examples
- 3.3 Special Examples
- 3.4 (Related) Definition of Hamiltonian Path
- 3.5 Examples
82. Euler Circuit
Leonhard Euler (pronounced OIL-er) 1707-1783,
Swiss Mathematician Is it possible for a person
to take a walk around the town of Königsberg,
starting and ending at the same location and
crossing each of the seven bridges exactly once?
92.1 Euler Circuit (Definition)
- Definition Let G(V,E) be a graph.
- An EULER CIRCUIT for G is a circuit that
contains every vertex in V and every edge in E. - Implications
- Circuit edges must be distinct
- At most 1 traversal of each edge.
- every edge in E
- At least 1 traversal of each edge.
- every vertex in V
- At least 1 traversal of each vertex.
102.2 Euler Circuit Theorem
- (Euler Circuit Theorem)
- Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree. - Proof Strategy
- () Assume G has an Euler Circuit
- Prove (1) G is connected
- (2) "vÎV, deg(v) 2k (for some k)
- () Assume G is connected and
- "vÎV, deg(v) 2k (for some k)
- Prove G has an Euler Circuit
112.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
- To Prove G is connected. (Defn of connected?)
- Since G has an Euler Circuit, then let
- v0 e1 v1 e2 v2 en-1 vn-1 en v0
- be the Euler Circuit.
- Pick any 2 vertices x, y in V.
- Now, x must be some vi and y must be some vj in
the Euler circuit. (Why? Since by definition,
An Euler circuit for G is a circuit that
contains EVERY VERTEX in V) - If i j then we have a walk from x vi ei1
vi1 ej vj y - If i gt j then we have a walk from x vi ei vi-1
ej1 vj y
- Therefore there is a walk from x to y in V.
- Therefore G is connected (by definition of
connected graph).
122.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Before we prove (2) Note that any vertex in a
circuit can be the starting vertex
1 2 3 5 6 3 1
2 3 5 6 3 1 2
3 5 6 3 1 2 3
5 6 3 1 2 3 5
6 3 1 2 3 5 6
3 1 2 3 5 6 3
132.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
- So in general, all these refer to the same
circuit - v0 e1 v1 e2 v2 en-1 vn-1 en v0
- v1 e2 v2 en-1 vn-1 en v0 e1 v1
- ..
- vn-1 en v0 e1 v1 e2 v2 en-1 vn-1
- It just depends on which vertex you want to take
as the starting vertex.
142.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
- Now, we prove (2)
- To show that any vertex has an even degree.
- Pick any vertex v in V.
- Since G has an Euler circuit, then that circuit
must pass through v (by defn of Euler circuit
circuit that contains EVERY VERTEX in V) - Look at the circuit from the viewpoint of v as
the starting vertex. - Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
152.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
If v has some more edges incident on it, the
process repeats again (Why? Because Euler Circuit
traverses every edge in E).
162.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
If v has some more edges incident on it, the
process repeats again (Why? Because Euler Circuit
traverses every edge in E).
172.2 Euler Circuit Theorem (Proof )
- Proof () Assume G(V,E) has an Euler circuit.
Show (1) G is connected, (2) ("vÎV, deg(v) 2k)
Each time v is exited through the use of one
edge, it must be returned to by the use of
another edge.
Edges on v occur in exit / entry pairs! Degree of
v must be a multiple of 2 gt EVEN!!!
182.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- The proof that there is () an Euler circuit,
will be given by an ALGORITHM for finding the
circuit. - We first present the algorithm.
- We next show that the algorithm is correct.
- (1) It will ALWAYS terminate and
- (2) If it terminates, it will ALWAYS find the
circuit.
192.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 1 Pick any vertex v ÎV as the starting
vertex. - Step 2 Pick any sequence of adjacent vertices
and edges starting and ending at v, and never
repeating an edge. Let this circuit be C.
C v 1 2 3 v
202.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3 Does C contain every edge and vertex of
G? - If Yes, then stop and output C, which is an
Euler circuit. - If No
1
2
v
3
C v 1 2 3 v
212.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3a Remove the circuit C from G creating G.
4
1
5
2
v
G
6
3
C v 1 2 3 v
222.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3a Remove the circuit C from G creating G.
4
1
5
G
6
3
C v 1 2 3 v
232.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3b Pick any vertex u common to C and G
4
1
5
6
u
3
C v 1 2 3 v
242.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C.
4
1
5
6
u
3
C v 1 2 3 v
252.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C.
4
1
5
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
262.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
4
1
5
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
272.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
4
1
5
C v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
282.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
(ii) Follow C to u
4
1
5
C v
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
292.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
302.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
312.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
322.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(iv) Return from u through untravelled portion
of C to v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
332.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3d PATCH C to C to form C
(iii) Follow C from u all the way back to u
(i) Start at v
(iv) Return from u through untravelled portion
of C to v
(ii) Follow C to u
4
1
5
C v 1 2 3 6 5 4 1 3 v
2
v
6
u
3
C v 1 2 3 v
C 3 6 5 4 1 3
342.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Let C C. Go back to Step 3
4
1
5
2
v
6
3
C v 1 2 3 6 5 4 1 3 v
352.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
Proof (The algorithm)
- Step 3 Does C contain every edge and vertex of
G? - If Yes, then stop and output C, which is an
Euler circuit. - If No (3a-3d)
4
1
5
2
v
6
3
C v 1 2 3 6 5 4 1 3 v
362.2 Euler Circuit Theorem (Proof )
- The algorithm
- Step 1 Pick any vertex v ÎV as the starting
vertex. - Step 2 Pick any sequence of adjacent vertices
and edges starting and ending at v, and never
repeating an edge. Let this circuit be C. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Pick any sequence of adjacent vertices
and edges of G, starting and ending at u, never
repeating an edge, creating another circuit C. - Step 3d PATCH C to C to form C
- Start at v
- Follow C to u
- Follow C from u all the way back to u
- Return from u through untravelled portion of C to
v - Let C C.
- Go to Step 3.
372.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- IF the algorithm terminates, THEN it will give an
Euler circuit. This is true because Step 3
checks whether all edges have been used, and step
3a ensures that no edge is repeated in the
circuit. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Create another ciruit C startin from u.
- Step 3d PATCH C to C to form C
382.2 Euler Circuit Theorem (Proof )
- Proof () Assume (1) G is connected, (2)
("vÎV, deg(v) 2k). Show G(V,E) has () an
Euler circuit.
- Proof
- (2) The algorithm will always terminate, because
- The graph is finite,
- Step 3b will always be successful since the
graph is connected, any remaining edges must
connect to the currently found circuit. - Step 2 and 3c will always be successful a new
circuit can always be found since the degree of
the vertex u is even. - Step 3 Does C contain every edge and vertex of
G? If Yes, then stop and output C, which is an
Euler circuit. If No, then - Step 3a Remove the circuit C from G creating G.
- Step 3b Pick any vertex u common to C and G
- Step 3c Create another circuit C starting from
u - Step 3d PATCH C to C to form C
392.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
402.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
412.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
C a b c d a
d
i
a
f
j
e
b
h
c
g
422.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
C a b c d a
d
i
C d e g h j i d
a
C a b c d e g h j i d a
f
j
e
b
h
c
g
432.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
C a b c d e g h j i d a
f
j
e
b
h
c
g
442.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
C a b c d e g h j i d a
f
j
e
b
h
c
C e f h e
g
C a b c d e f h e g h j i d a
452.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A Yes
Q Where is the Circuit?
d
i
a
f
j
e
b
h
c
g
C a b c d e f h e g h j i d a
C is the Euler Circuit
462.3 Example
- (Euler Circuit Theorem) Let G(V,E) be a graph.
- G has an Euler circuit iff G is connected AND
every vertex of G has even degree.
Q Does the graph have an Euler circuit
A No.
472.4. Euler Path (Definition)
- Definition Let G(V,E) be a graph.
- An EULER PATH from v to u (v ? u) for G is a
path starting from v and ending at u and contains
every vertex in V and every edge in E. - Implications
- Path edges must be distinct
- At most 1 traversal of each edge.
- every edge in E
- At least 1 traversal of each edge.
- every vertex in V
- At least 1 traversal of each vertex.
482.5 Euler Path Theorem
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree. - Euler Path theorem is a COROLLARY (a consequence,
a result) of Euler Circuit theorem. - Proof is left as an exercise (You need to use the
Euler circuit theorem to prove the Euler Path
theorem).
492.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
502.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
a
g
h
A a g h i e h f a
i
b
e
f
k
c
d
j
512.6 Euler Path Theorem (Example)
- (Euler Path Theorem) Let G(V,E) be a graph.
- G has an Euler Path from v to u iff G is
connected AND v and u have odd degree and every
other vertex of G has even degree.
Q Does the graph have an Euler path from a to d?
A Yes. Degree a and d are odd. All other
degree are even.
Q Where is the Path?
a
g
h
A a g h i e h f a
b f e k j d b c d
i
b
e
f
k
c
d
j
52A. Circuits
- Definitions (Closed Walk, Circuit, Simple
Circuit) and Examples - 2. A special kind of circuit
- 2.1 Definition of Euler Circuit
- 2.2 Euler Circuit Theorem and Proof
- 2.3 Examples
- 2.4 (Related) Definition of Euler Path
- 2.5 Euler Path Theorem
- 2.6 Example
- 3. A special kind of simple circuit
- 3.1 Definition of Hamiltonian Circuit
- 3.2 Examples
- 3.3 Special Examples
- 3.4 (Related) Definition of Hamiltonian Path
- 3.5 Examples
533.1. Hamiltonian Circuit (Definition)
- Definition Let G(V,E) be a graph.
- A HAMILTONIAN CIRCUIT for G is a simple circuit
that contains every vertex in V. - (Sir William Hamilton 1805-1865, Irish)
- Implications
- Simple circuit
- vertices must be distinct
- AT MOST ONE traversal of each vertex
- every vertex in V
- AT LEAST ONE traversal of each vertex
- Simple circuit (edges distinct of course!)
543.2 Hamiltonian Circuit (Examples)
Q Is there a Hamiltonian circuit?
A Yes
g
b
d
a
f
h
e
c
g
553.3 Hamiltonian Circuit (Theorem?)
- Q Given ANY graph G(V,E), is there a nice
property which is a sufficient condition to
determine whether the graph has a Hamiltonian
circuit? - (Sufficient condition) Property Hamiltonian
Circuit - A Dont know. No choice but to try all possible
ways. - Q Are there special types of graphs which
definitely have Hamiltonian circuits? - A Yes.
- Q What are they?
- A Graphs of some forms of geometric solids.
- (i) Platonic Solids (ii) Archimedian solids
563.3 Hamiltonian Circuit (Special Cases)
(i) Platonic Solids
573.3 Hamiltonian Circuit (Special Cases)
(ii) Archidemian Solids
583.4. Hamiltonian Path (Definition)
- Definition Let G(V,E) be a graph.
- A HAMILTONIAN Path for G is a simple path that
contains every vertex in V. - Implications
- Simple path
- vertices must be distinct
- AT MOST ONE traversal of each vertex
- every vertex in V
- AT LEAST ONE traversal of each vertex
- Simple path (edges distinct of course!)
593.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q But does it have a Hamiltonian Path from a
to c? A Yes a e h f d b g c
603.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Does it have a Hamiltonian Path from a to
g? A No.
613.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be Hamiltonian Paths starting from
g? A No.
623.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be Hamiltonian Paths ending at d? A
No.
633.5 Hamiltonian Path (Example)
- Example The following graph does not have a
Hamiltonian circuit.
Q Can there be a Hamiltonian Path ending at
a? A Yes. Example b g c d f e h
64B. Graph Representation
- Graph Representation using Matrices
- 2. Using matrices to find information.
- 2.1 Q Is the graph directed or undirected?
- 2.2 Q How many connected components are there?
- 2.3 Q Is there a walk of length n from v to u?
651. Graph Representation using matrices
- There are 2 main ways to represent graphs in the
computer - Use a 2D array.
- Use an adjacency lists.
- (Graph implementation taught in cs1102)
- Using a 2D array corresponds to using a adjacency
matrix representation. - IMPT We assume you know (1) basic matrix
terminology and (2) matrix multiplication
(Please refer to p646-651 for your personal
revision, if you need to).
661. Graph Representation using matrices
- An m x n matrix A over a set S, is a rectangular
array of elements of S arranged into m rows and n
columns.
671. Graph Representation using matrices
- A graph with n vertices can be represented using
a n x n adjacency matrix. - Each entry aij of the matrix is used to indicate
the presence or absence of an edge from vi to vj.
682. Using matrices to find information
- Let A be the adjacency matrix representation of
some graph G. - Looking only at the matrix (i.e. do not draw the
graph), how do we know - Q1 whether the graph is directed or
undirected? - Q2 how many connected components are there in
the graph? - Q3 whether is there a walk of length w from vi
to vj?
692.1 Directed or undirected graph?
- Q1 How do we know whether the graph is a
directed or an undirected graph? - A The graph is undirected iff "i,j, aij aji.
Symmetric
702.1 Directed or undirected graph?
- Q1 How do we know whether the graph is a
directed or an undirected graph? - A The graph is undirected iff "i,j, aij aji.
NOT Symmetric
712.1 Directed or undirected graph?
- Q1 How do we know whether the graph is a
directed or an undirected graph? - A The graph is undirected iff "i,j, aij aji.
Why? If there is an edge from vi to vj , (aij
1) and since the graph is undirected, then there
is also an edge from vj to vi (aji
1). Similarly, if there is no edge from vi to vj
, (aij 0) then there is also no edge from vj to
vi (aji 0).
722.2 How many connected components?
- Q2 How do we know how many connected components
are there in the graph?
732.2 How many connected components?
- Q2 How do we know how many connected components
are there in the graph?
v6
v2
v1
v4
v5
v3
v7
742.2 How many connected components?
- Q2 How do we know how many connected components
are there in the graph?
v6
v2
v1
v4
v5
v3
v7
752.2 How many connected components?
- Q2 How do we know how many connected components
are there in the graph?
v6
v2
v1
v4
v5
v3
v7
762.2 How many connected components?
- Q2 How do we know how many connected components
are there in the graph?
3 connected components
v6
v2
v1
v4
v5
v3
v7
772.2 How many connected components?
- In general, if the graph has k connected
components, each with ni vertices then there
exist a way to swap the rows and columns of the
matrix so that the vertices of the connected
components are arranged together, resulting in a
matrix of the form
Each Ai is a adjacency matrix of ni
vertices. Each O is a matrix with all entries as
0.
782.2 How many connected components?
- There exists a way doesnt tell you how to
deterministically find the way. (Not part of
our syllabus). - There are algorithms which break a graph into
connected components (which will be covered in
other courses)
792.3 Walk from vi to vj of length w?
- Q3 How do we know whether there is a walk from
vi to vj of length w?
Q Is there a walk from v1 to v2 of length 1?
A Yes.
Q Is there a walk from v1 to v2 of length 2?
A No.
802.3 Walk from vi to vj of length w?
- Q3 How do we know whether there is a walk from
vi to vj of length w?
v1
Q Is there a walk from v1 to v2 of length 1?
A Yes.
Q Is there a walk from v1 to v2 of length 2?
v2
v3
A No.
Q Is there a walk from v2 to v3 of length 2?
v4
v5
A Yes, 3 such walks.
812.3 Walk from vi to vj of length w?
- Q3 How do we know whether there is a walk from
vi to vj of length w?
v1
Q Is there a walk from v1 to v2 of length 3?
A Yes.
v2
Q How many of such walks?
v3
A 6.
Q Is there a walk from v2 to v3 of length 3?
v4
v5
A No.
822.3 Walk from vi to vj of length w?
- Theorem Let G (V,E) and V v1,v2,,vm and
let A be the adjacency matrix of G. "n gt 1, - The i-j-th entry of An the number of walks of
length n from vi to vj ("i,jÎ1..m)
Proof by induction on n
- Base case (n1)
- The i-j-th entry of A1 the number of walks of
length 1 from vi to vj ("i,jÎ1..m) - This is true since the i-j-th entry of A is 1 if
there is an edge and 0 otherwise. - If there is an edge, then there is a walk of
length 1 from vi to vj.
832.3 Walk from vi to vj of length w?
- Theorem Let G (V,E) and V v1,v2,,vm and
let A be the adjacency matrix of G. "n gt 1, - The i-j-th entry of An the number of walks of
length n from vi to vj ("i,jÎ1..m)
Proof by induction on n
- Inductive case (k k1)
- Let aij be used to denote elements in A.
- Let bij be used to denote elements in Ak.
- Let cij be used to denote elements in Ak1.
- Assume The i-j-th entry of Ak the number of
walks of length k from vi to vj ("i,jÎ1..m) - To Prove The i-j-th entry of Ak1 the number
of walks of length k1 from vi to vj ("i,jÎ1..m)
842.3 Walk from vi to vj of length w?
ai1b1j ai2b2j ai3b3j aimbmj cij
ai1b1j Walk of Length 1 from vi to v1 x
Walk of Length k from v1 to vj. (IH) Walk
of Length k1 from vi to vj with v1 as 2nd
vertex
852.3 Walk from vi to vj of length w?
j
j
i
i
A
Ak
Ak1
ai1
ai2
aim
b1j
b2j
bmj
ai1b1j ai2b2j ai3b3j aimbmj cij
ai2b2j Walk of Length 1 from vi to v2 x
Walk of Length k from v2 to vj. (IH) Walk
of Length k1 from vi to vj with v2 as 2nd
vertex
862.3 Walk from vi to vj of length w?
j
j
i
i
A
Ak
Ak1
ai1
ai2
aim
b1j
b2j
bmj
ai1b1j ai2b2j ai3b3j aimbmj cij
ai3b3j Walk of Length 1 from vi to v3 x
Walk of Length k from v3 to vj. (IH) Walk
of Length k1 from vi to vj with v3 as 2nd
vertex
872.3 Walk from vi to vj of length w?
j
j
i
i
A
Ak
Ak1
ai1
ai2
aim
b1j
b2j
bmj
ai1b1j ai2b2j ai3b3j aimbmj cij
aimbmj Walk of Length 1 from vi to vm x
Walk of Length k from vm to vj. (IH) Walk
of Length k1 from vi to vj with vm as 2nd
vertex
882.3 Walk from vi to vj of length w?
j
j
i
i
A
Ak
Ak1
ai1
ai2
aim
b1j
b2j
bmj
ai1b1j ai2b2j ai3b3j aimbmj cij
All walks of length k1 from vi to vj can only
pass through v1 to vm as their second vertex.
(There are no other vertices to pass
through). Therefore cij will store the number of
walks from vi to vj of length k1. (Proven the
k1 case)
89