Computing Fundamentals 2 Lecture 1 A Theory of Graphs - PowerPoint PPT Presentation

1 / 116
About This Presentation
Title:

Computing Fundamentals 2 Lecture 1 A Theory of Graphs

Description:

Computing Fundamentals 2 Lecture 1 A Theory of Graphs Lecturer: Patrick Browne Room [KA] - 3-020, Lab [KA] - 1-017 Based on Chapter 19. A Logical approach to Discrete ... – PowerPoint PPT presentation

Number of Views:242
Avg rating:3.0/5.0
Slides: 117
Provided by: pbrowne
Category:

less

Transcript and Presenter's Notes

Title: Computing Fundamentals 2 Lecture 1 A Theory of Graphs


1
Computing Fundamentals 2Lecture 1 A Theory of
Graphs
  • Lecturer Patrick Browne
  • Room KA - 3-020, Lab KA - 1-017
  • Based on Chapter 19.
  • A Logical approach to Discrete Math
  • By David Gries and Fred B. Schneider
  • http//www.comp.dit.ie/pbrowne/compfund2/compfun2.
    htm

2
A Theory of Graphs
  • We all have an intuitive understanding of graphs.

3
A Theory of Graphs
Question Starting at Newport is it possible to
travel each road exactly once and return to
Newport?
4
Some terminology
  • In graph theory terms, the dots on the map are
    called vertices and the lines that connect the
    vertices are called edges. We have labelled the
    edges e1..e13. If we travel from Newport to Cork
    we call this a path from Newport to Cork.
  • The graph can be written as G ltV,Egt
  • V Newport, Sligo, Athlone, Drogheda, Dublin,
    Carlow, Waterford, Cork, Limerick, Galway
  • E e1, e2, e13
  • This is an undirected graph, there are no one-way
    streets.

5
Rephrasing the question
  • Question Starting at Newport is it possible to
    travel each road exactly once and return to
    Newport?
  • Our problem can be restated
  • Is there a path from vertex Newport to vertex
    Newport that traverses each edge exactly once?

6
Reasoning about the question
  • Suppose there was such a path consider the vertex
    Limerick. Each time we arrive at Limerick on some
    edge , we must leave using a different edge.
    Furthermore, every edge that touches Limerick
    must be used.

7
Reasoning about the question
  • Thus the edges at Limerick occur in in/out pairs.
    It follows that an even number of edges must
    touch Limerick. Since three edges touch Limerick
    (e6,e9,e11) we have a contraction. Therefore,
    there is no path from Newport to Newport that
    traverses every edge once. We have proved this
    using graph theory.

8
Algorithms in proofs
  • An algorithm is a finite list of well-defined
    instructions for accomplishing some task that,
    given an initial state, will proceed through a
    well-defined series of successive states,
    possibly eventually terminating in an end-state1.
  • The proof of some results in graph theory may
    involve an algorithm to construct some object
    like a path from one vertex to another. In
    Chapter 19 of Gries and Schneider algorithms are
    used in proofs2

9
Graphs and Multigraphs
  • (19.1) Definition Let V be a finite, non empty
    set and let E be a binary relation on V. Then
    GltV,Egt is called a directed graph or a digraph.
    An element of V is called a vertex an element of
    E is called an edge.
  • The binary relation E is defined as E?VV.
  • In figure 19.1 E and V are
  • E ltb,bgt,ltb,cgt,ltb,dgt,ltc,egt,lte,cgt,lte,dgt
  • V a,b,c,d.e
  • A digraph GltV,Egt is loop free iff E is an
    irreflexive relation (no ltb,bgt ).

10
A directed graph or digraph
c
Fig. 19.1
e
a
b
V a,b,c,d.e E ltb,bgt,ltb,cgt,ltb,dgt,ltc,egt,lte,cgt
,lte,dgt
d
An undirected graph represented as a digraph
b
d
b
a
d
Here E is a set of unordered pairs i.e a,b
rather than lta,bgt.
a
a,b, a,c, b,c, b,d these are sets
c
a,b could be written lta,bgt, ltb,agt.
c
Fig. 19.2b
Fig. 19.2 a
There is a one-to-one correspondence between
undirected graphs and digraphs with symmetric
relations.
11
Aside Bags
  • The elements of a set are distinct. Sometimes we
    need to allow duplicates. For example, if we
    wanted to count the people in Dublin using a list
    of their names we would have to allow for
    duplicate names, a set would not be appropriate.
    Mathematically a bag is a set with duplicates
    therefore many of the familiar set operations
    apply to bags.

12
Graphs and Multigraphs
  • A multigraph is a pair ltV,Egt, where V is a set
    of vertices and E is a bag of undirected edges.
  • In a multigraph there can be many edges between
    two given vertices. Every undirected graph is a
    multigraph (but not visa versa).
  • Multigraphs do not depict relations.
  • In order to distinguish edges in a multigraph we
    can label the edges.

13
Graphs and Multigraphs
Eulers 7 bridges of Konigsberg, representing
bridges as edges, land as vertices.
               ?                ?
              
6
3
1
5
2
4
7
Because a multigraph consists of a bag of
undirected edges we need labels to distinguish
edges. This means that they may be parallel edges
between two given vertices.
14
The Degree of A Vertex and Graph
  • The indegree of a vertex of a digraph is the
    number of edges for which it is an end vertex.
  • The outdegree is the number of edges for which it
    is a start vertex.
  • The degree of a vertex, written deg.v, is the sum
    of the indegree and the outdegree.
  • A vertex whose degree is 0 is called isolated.
  • The degree of a vertex of an undirected graph or
    multigraph is the number of edge ends attached to
    it.

15
The Degree of A Vertex and Graph
  • Each edge contributes 1 to the degree of two
    vertices (which in a loop may be the same vertex,
    thus adds two to that vertex).
  • (19.3) Theorem. The sum of the degrees of the
    vertices of a digraph or multigraph is 2 E (E
    is a set, see next slide).
  • (19.4) Corollary. In a digraph or a multigraph
    the number of vertices of odd degree is even.

16
The Handshaking Theorem
Theorem Let G(V,E) be an undirected graph. Then
twice the number of edges is equal to the sum of
the degrees of V. Number of edges
7 1 2 3 2 2 3 1
14 In any group of people the number of people
who have shaken hands with an odd number of other
people from the group is even. Zero is an even
number
17
Even degree
  • Loop edge gives vertex a degree of 2.
  • In any graph the sum of degrees of all vertices
    equals twice the number of edges.
  • The total degree of a graph is even.
  • In any graph there are even number of vertices of
    odd degree.

18
Paths
  • The land masses are modelled as vertices. The
    bridges are modelled as edges. Is it possible to
    tour Königsberg in a way that would traverse each
    bridge (edge) exactly once?

Deg(d) 5 Deg(a) 3 Deg(b) 3 Deg(c)
3 --------------- 14 Edges 7 (2 x
Edges) 14
Fig. 19.3(b)
19
Aside A theory of Sequences
  • A sequence is a finite list of elements from some
    set. The theory of sequences can be used to
    reason about graphs, lists and arrays.
  • Sequences are ordered, but not necessarily
    sorted. Like runners in a race there is a first,
    second and third runner. Their finishing position
    in the race does not usually depend on their race
    number. At the finish runners are not (usually!)
    sorted by race number.

20
Aside A theory of Sequences
  • Catenation When we join two sequences together
    we want to preserve the position of each element.
    This can be illustrated by using the CafeOBJ
    sequence module.
  • red 1 , 2 1, 2, 3 , 4 0
  • Giving
  • 1, 2, 1, 2, 3, 4, 0
  • Note that duplicates are allowed.

21
Path
  • A path of a multigraph or a digraph is a sequence
    of vertices and edges that would be traversed
    when walking the graph from one vertex to
    another, following the edges, but with no edge
    traversed more than once. In a directed graph an
    edge can only be traversed in one direction.

22
Paths Example
  • A path that starts at vertex b and ends at vertex
    c is called a b-c path. Here represented as a
    sequence of vertices and edges.

c
e
a
b
Fig. 19.1
d
  • Path1 ltc,ltc,egt,e,lte,dgt,dgt
  • Path2 ltb,ltb,cgt,c,ltc,egt,e,lte,cgt,cgt
  • Non-Path ltb,ltb,cgt,c,ltc,egt,e,lte,cgt,c,ltc,egt,egt

23
Path length, alternative notation
The length of a path is the number of edges in
it. Path3 lta,6,b,5,d,1,agt Length 3 edges
Fig. 19.3(b)
24
Path intermediate summary
  1. A path starts with a vertex, ends and alternates
    between vertices and edges.
  2. Each directed edge in a path is preceded by its
    start vertex and followed by its end vertex. An
    undirected edge is preceded by one of its
    vertices followed by the other.
  3. No edge appears more than once.
  4. The length of a path is the number of edges on
    it. The path with just one vertex ltagt has length
    zero. A self loop ltb,bgt is a cycle of length
    one.

25
Redundant Notation
  • The notation (lta,6,b,5,d,1,agt) can be used for
    all graphs (directed, undirected and
    multigraphs).
  • While the notation is necessary for multigraphs
    it is redundant for directed and undirected
    graphs (even though they are simple by 2
    multigraphs!).
  • In a digraph, for any two vertices b and c, there
    is at most one edge from b to c.
  • Similarly, in any undirected graph, there is at
    most one edge between two given vertices.
  • No need to show edges for directed and undirected
    graphs, hence
  • Path1 ltc,e,dgt. just vertices
  • But labelling is required for multigraphs.

26
Simple Path
  • A simple path is a path in which no vertex
    appears more than once (first and last may be
    same). Examples from Fig. 19.1
  • ltagt an isolated node, a path with no edges,len0
  • ltb,bgt loop, firstlast gt cycle, length1
  • ltb,c,e,dgt
  • ltb,c,e,cgt not simple path

27
An Example of a Simple-Path
  • In the following diagram the red edges show a
    simple path of length 3 from a to e. The simple
    path is acde of length 3. We could also have a
    non-simple path acdabde of length 6.
  • A simple path no vertex appears more than once.

a
c
b
d
e
28
d
X b
Z c
y
Uses sequence notation
29
(No Transcript)
30
Cycle
  • A path with at least one edge and with the first
    and last vertices the same is called a cycle.
  • (19.7) Theorem Suppose all the vertices of a
    loop free multigraph have even degree. Suppose
    deg.b gt 0 for some vertex b. Then some cycle
    contains b. Note, zero is an even number and is
    neither positive nor negative.
  • Note that unlike paths, any vertex of a cycle can
    be chosen as the start, so the start is sometimes
    not specified.

31
Connected Graph
  • A undirected multigraph is connected if there is
    a path between any two vertices.
  • A digraph is connected if making its edges
    undirected results in a connected multigraph.

32
digraph not connected
c
e
a
b
Fig. 19.1
d
Connected graphs
b
d
a
c
Fig. 19.2 a
  • The graph in Fig 19.1 is not connected, the
    graphs in Fig 19.2a and Fig 19.3b are connected.

33
Connected Directed Graph1
  •   There are three distinct forms of connectedness
    in simple directed graphs weakly connected,
    unilaterally connected and strongly connected. 

A directed graph is strongly connected if every
two vertices are reachable from each other.
Unilaterally connected graphs need the concept of
semi-path, which we do not cover.
34
Path Simple Path? Cycle? Simple
Cycle? lt6,5,2,4,3,2,1gt no
no no lt6,5,2,4gt yes no no lt2,6,5,2,4,3,2gt
no yes no lt5,6,2,5gt yes(book def)
yes yes lt7gt yes no no (length0)
We have a path when no edge traversed more than
once. A simple path from. v to w is a path from v
to w with no repeated vertices. (first last
may be the same) ltv0,e1,v1,e2,v2,,vn-1,en,vngt
where v0v and vnw A cycle (or circuit) is a
path of nonzero length from v to v with no
repeated edges Must return to start. A simple
cycle is a cycle is a non-zero sequence of
vertices and edges, from v to v in which, except
for the beginning and ending vertices that are
both equal to v, there are no repeated vertices.
35
Graph Representation 1
v w x y
v 0 1 0 1
w 1 0 1 1
x 0 1 0 1
y 1 1 1 0
  • Adjacency matrix
  • Rows and columns are labeled with ordered
    vertices write a 1 if there is an edge between
    the row vertex and the column vertex and 0 if no
    edge exists between them

36
Graph Representation 2
e f g h j
v 1 1 0 0 0
w 1 0 1 0 1
x 0 0 0 1 1
y 0 1 1 1 0
  • Incidence matrix
  • Label rows with vertices
  • Label columns with edges
  • 1 if an edge is incident to a vertex, 0 otherwise


37
Three applications of Graphs
  • The Konigsberg Bridge Problem
  • The Celebrity Problem
  • Route finding
  • The states of river crossing puzzle (slides
    towards end of this lecture).

38
Celebrity problem uses a directed graph
  • At a party, a celebrity is a person who everyone
    knows and who knows no one (except themselves).
  • In graph theory terms what would be represented
    by nodes and vertices?
  • Would the graph be directed or undirected?

39
Definition Application of Euler Cycle
  • An Euler cycle is a cycle in a graph that
    includes each edge exactly once. Examples
    Designing and optimizing routes for refuse
    trucks, snow ploughs, or postmen. In all of
    these applications, every edge in a graph must be
    traversed at least once. For example, roads in a
    city must be completely traversed at least once
    in order to ensure that all rubbish is collected,
    all snow cleared, all post delivered. We seek
    to minimize total time, or the total distance or
    number of edges traversed. It may not always be
    possible to travel each edge exactly once and a
    near optimal solution may have to be used.

40
Euler Path
  • An Euler path in a multigraph is a path that
    contains each edge exactly once. If the first and
    last vertices are the same then the Euler path is
    called an Euler cycle (or circuit). Example G1
    has Euler path from a to b
  • a, c, d, e, b, d, a, b

a
b
Graph G1
c
d
e
41
Euler Path
  • a, c

a
b
c
d
e
42
Euler Path
  • a, c, d

a
b
c
d
e
43
Euler Path
  • a, c, d, e

a
b
c
d
e
44
Euler Path
  • a, c, d, e, b

a
b
c
d
e
45
Euler Path
  • a, c, d, e, b, d

a
b
c
d
e
46
Euler Path
  • a, c, d, e, b, d, a

a
b
c
d
e
47
Euler Path
  • a , c, d, e, b, d, a, b

a
b
c
d
e
48
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
49
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
50
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
51
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
52
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
53
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
54
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
55
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
56
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
57
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
58
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
59
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
60
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
61
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
62
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
63
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
64
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
65
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
66
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
67
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
68
Euler Cycle
Euler cycle a,d,c,i,j,n,o,k,j,d,e,k,l,h,m,g,h,f,
e,b,a
a
b
g
f
c
d
e
h
j
k
l
i
m
o
n
69
Euler Cycles and Paths
a
b
c
d
e
70
The general theory from the Konigsberg Bridge
Problem
  • (19.8) Theorem. An undirected connected
    multigraph has an Euler circuit iff every vertex
    has even degree.
  • Euler Circuit Even Degree
  • The proof is in two parts
  • (1) LHS gt RHS and (2) RHS gt LHS
  • This is called proof by mutual implication.

71
Example Proof
  • Euler Circuit (EC) Even Degree (ED)
  • (1) LHS gt RHS
  • This says Euler Circuit gt is of even degree.
  • Assume that the multigraph has an EC as below

e0
e1
en
v0
v1
v2
vn
  • Each vertex vi on the EC is preceded by an edge,
    and followed by an edge, and each of the two
    edges contributes 1 to the degree of vi. Since
    all the edges appear in the circuit the degree of
    each vi is even.

72
Proof(2)
  • Euler Circuit(EC) Even Degree(ED)
  • (2) RHS gt LHS
  • Long proof. We will not cover the second part of
    this proof. If interested, see course text.

73
A Simple Graph
  • A graph with neither loops nor parallel edges is
    called a simple graph (we are talking about
    graphs not paths).

G2
G1
The graph G1 is a simple graph. The graph G2 is
not a simple graph
74
A Complete Graph
  • A complete graph on n vertices, Kn, is the simple
    graph (no loops or parallel edges) with n
    vertices in which there is an edge between every
    pair of distinct vertices. In general, the
    complete graph, Kn, is a simple graph with n
    vertices, each of which has degree n - 1.

Example K4 n vertices and n(n - 1) / 2
edges 4(4-1)/2 6 edges
In any graph, the number of vertices with odd
degree is even. In K4 each vertex is of odd
degree 333312 2 6 2E
K4
75
Some Complete graphs with number of edges.
K10 K21 K33 K46
                                               
K510 K615 K721 K828
                                                                           
76
Bipartite Graph
  • A graph GltV,Egt is bipartite if there exists
    subsets V1 and V2 (either possibly empty) of V
    such that V1?V2 ? , V1?V2 V (i.e. a
    partition), and each edge in E is incident on one
    vertex in V1 and one vertex in V2 . A bipartite
    graph is a graph that does not contain any
    odd-length cycles.

A bipartite graph V1 v1 , v2 , v3 V2 v4, v5
, V1?V2 ? , V1?V2 V
v1
v4
v2
v5
v3
V1
V2
77
Bipartite Graph
  • A graph GltV,Egt is bipartite if there exists
    subsets V1 and V2 (either possibly empty) of V
    such that V1?V2 ? , V1?V2 V (i.e. a
    partition), and each edge in E is incident on one
    vertex in V1 and one vertex in V2 . A bipartite
    graph is a graph that does not contain any
    odd-length cycles.

V1
V2
78
A Complete Bipartite Graph
  • The complete bipartite on m and n vertices Km,n ,
    is the simple graph whose vertex set are
    partitioned into two sets V1 with m vertices and
    V2 with n vertices in which there is an edge
    between each pair of vertices, where v1 is in V1
    and v2 is in V2 .

A complete bipartite graph K2,4
V1
V2
79
Application of bipartite graphs
  • Bipartite graphs can be used to represent
    relations.
  • Bipartite graphs can be used for mapping workers
    to possible jobs.
  • Bipartite graphs are used in Petri nets to model
    processes. Nodes represent transitions
    (events-bars) and places (conditions-circles).
    The directed arcs describe which places are
    conditions for which transitions (arrows).

80
Application of bipartite graphs
The graph K3,3 is called the utility graph. This
usage comes from a standard mathematical puzzle
in which three utilities must each be connected
to three buildings it is impossible to solve
without crossings due to the non-planarity of
K3,3.
81
Finding Bipartite graph
  • Use two colours say blue red. Such a colouring
    of the vertices of a bipartite graph means that
    the graph can be drawn with the red vertices on
    the left and the blue vertices on the right such
    that all edges go from left to right. Colour the
    first vertex blue, and then do a depth-first
    search of the graph. Whenever we discover a new,
    uncoloured vertex, colour it opposite that of its
    parent, since the same colour would cause a
    clash. If we ever find an edge where both
    vertices have been coloured identically, then the
    graph cannot be bipartite. Otherwise, this
    colouring will be a 2-colouring and can be
    constructed.

82
Depth First Search (DFS)
We will cover graph traversal and searching in
the next lecture Original Graph
DFS
1
4
2
7
5
3
6
The edges are traversed in the order specified by
the numbers above.
83
Bipartite Example
  • G1 is bipartite because it can be two coloured,
    blue for the centre and red for the rest.
  • G2 (K3) is not bipartite because it cannot be two
    coloured. If we make V1 red then V2 and V3 must
    be blue, but V2 is connected to V3. Hence, blue
    to blue which is not allowed. It will be the same
    no matter where we start.

3
84
Finding a bipartition using parity
0
1
Even parity
1
2
3
4
Odd parity
4
5
4
85
Bipartite Example
The graph is bipartite because every edge goes
between an odd-numbered vertex (red) and an even
numbered vertex (blue), giving


V 1,3,5,7
U 2,4,6,8
2
2
1
3
4
1
4
6
3
7
5
8
8
6
7
5
86
Bipartite Example
3
2
2
1
4
1
4
6
5
3
6
5
87
K-colouring graphs
88
K-colouring graphs
A k-colouring partitions of the vertex set into
k independent sets.
89
Sub-graph
Some subgraphs of G1
Graph G1
v2
v2
e10
e11
e10
e11
e8
e5
e8
e5
90
Sub-graph
The four possible subgraph G
Graph G
v2
v2
v2
v2
e1
e1
v1
v1
v1
v1
Graph G G1
G2 G3 G4
91
Bipartite Graph
  • (19.10) Theorem. A path of a bipartite graph is
    of even length iff its ends are in the same
    partition.

v1
v4
v2
v5
v3
V1
V2
92
Bipartite Graph
  • (19.11) Corollary. A connected graph is bipartite
    iff every cycle has even length e.g. look at the
    cycle ltv3,v5,v2,v4,v3gt.

v1
v4
v2
v5
v3
V1
V2
93
Bipartite Graph
  • Another example of (19.11)

V1
V2
94
Complete Bipartite Graphs
K1,3 K2,3
K3,3
95
Example
  • Has the following graph got a Euler cycle. If it
    has what is it.
  • Solution No Euler Cycle, vertex b has odd degree.

c
d
b
e
a
g
f
In general if you should test for existence,
before trying to find Euler cycle
96
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, all vertices of even degree.

v1
v2
v3
v4
v5
97
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3gt

v1
v2
v3
v4
v5
98
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5gt

v1
v2
v3
v4
v5
99
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2gt

v1
v2
v3
v4
v5
100
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4gt

v1
v2
v3
v4
v5
101
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5gt

v1
v2
v3
v4
v5
102
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5,v1gt

v1
v2
v3
v4
v5
103
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5,v1,v4gt

v1
v2
v3
v4
v5
104
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5,v1,v4,v3gt

v1
v2
v3
v4
v5
105
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5,v1,v4,v3,v2gt

v1
v2
v3
v4
v5
106
Example
  • Has the following graph got a Euler cycle? If it
    has what is it.
  • Solution Yes, ltv1,v3,v5,v2,v4,v5,v1,v4,v3,v2,v1gt

v1
v2
v3
v4
v5
107
Example
  • Draw a graph with 4 edges and 4 vertices ,
  • having degrees 1,2,3,4.
  • No such graph exists, because Handshaking
    Theorem(HT) says
  • 2 numberOfEdges(E) sum(deg(V))
  • but
  • 2 4 / 1234
  • Which is not consistent with HT

108
c
e
a
b
Fig. 19.1
d
Sequence Path? Simple Path? Cycle? Simple
Cycle? ltc,e,dgt ltb,c,e,c,egt lte,c,egt ltb,bgt ltb
gt
109
A Theory of Graphs1
110
A Theory of Graphs
  • mod GRAPH
  • Vertex Edge
  • -- Notation from Chapter 19 Gries and Schneider
  • -- We have two operations called s t on edges.
  • -- Both operations take an Edge and return a
    Vertex
  • -- which can be either source or target
  • op lt_,_gt Vertex Vertex -gt Edge
  • op s Edge -gt Vertex
  • op t Edge -gt Vertex

111
A Theory of Graphs
  • -- General graph equations
  • vars a b Vertex
  • eq s(lt a , b gt) a .
  • eq t(lt a , b gt) b .
  • -- A particular instance of graph
  • ops e1 e2 e3 -gt Edge
  • ops v1 v2 v3 -gt Vertex
  • eq e1 lt v1 , v2 gt .
  • eq e2 lt v2 , v3 gt .
  • eq e3 lt v3 , v1 gt .

112
A Theory of Graphs
  • -- v1---e1---v2----e2---v3
  • --
  • -- ----------e3--------------
  • open GRAPH
  • -- What is the start of e1 ?
  • red s(e1) . v1
  • -- Is e1 connect to e2?
  • red t(e1) s(e2) . true

113
A directed graph or digraph G1
c
e
a
b
Fig. 19.1
d
An undirected graph represented as a digraph
b
d
b
a
d
a
c
c
Fig. 19.2b
Fig. 19.2 a
114
Sample Graph g2
v1
Graph g2
v4
v2
v5
v3
115
Sample Graph g3
v3
v6
Graph g2
v1
v5
v2
v7
v4
116
Sample Graph Path
a
e
n1
n5
n2
f
d
b
n3
c
n4
Graph with paths see CafeOBJ specification.
Write a Comment
User Comments (0)
About PowerShow.com