graphs. definition a simple graph g= (v, e) consists of vertices, v, a nonempty set of vertices,...

48
Graphs

Upload: gavin-warren

Post on 13-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Graphs

Page 2: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition A simple graph G= (V, E) consists of vertices, V, a

nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges.

Page 3: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

•- no arrows

•- no loops

•- can't have multiple edges joining vertices

A simple graph

Page 4: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

DefinitionA multigraph G=(V, E) consists of a set V of

vertices, a set E of edges, and a function f from E to {{u, v} | u, v V, u v}. The edges e1 and e2 are called multiple or parallel edges if f(e1) = f(e2).

Page 5: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

A multigraph

 No loop is allowed.

• Multiple edges are allowed.

Page 6: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

DefinitionA pseudograph G = (V, E) consists of a set V of

vertices, a set E of edges, and a function f from E to {{u, v} | u, v V}. An edge is a loop if f(e) = {u, v} for some v V.

Page 7: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements
Page 8: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition◦ A directed graph (V, E) consists of a set of a set of

vertices V and a set of edges E that are ordered pairs of elements of V.

Page 9: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

 Loops, ordered pairs or the same element, are allowed.

  Multiple edges in the same direction between two vertices are not allowed.

A directed graph

Page 10: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition◦ A directed multigraph G = (V, E) consists of a set

V of vertices, a set E of edges, and a function f from E to {(u, v) | u, v V}. The edges e1 and e2 are multiple edges if f(e1) = f(e2).

Page 11: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

•Loops, ordered pairs or the same element, are allowed.

 

Multiple edges in the same direction between two vertices are allowed.

A directed multigraph

Page 12: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Summary

Type Edges Multiple edges allowed?

Loops allowed?

Simple graph

Undirected No No

Multigraph Undirected Yes No

Pseudograph Undirected Yes Yes

Directed graph

Directed No Yes

Directed multigraph

Directed Yes Yes

Page 13: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements
Page 14: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

There will be an edge (a, b) from team a to team b, if team a beats team b.

Page 15: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

• Adjacent:

• Two vertices u and v in an undirected graph G

are called adjacent (or neighbours) if {u, v} is an

edge of G.

• If e = {u, v} the edge e is called incident with u and v. The edge e is also said to connect u and v. The vertices u and v are called endpoints of the edge {u, v}.

15

Page 16: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

a bc

de

e1 e2

e3

e4

e5

e6

• Vertex a is adjacent to b because there is an edge e1 that connects vertices a and b.

 • Edge e4 is incident with vertices a and d.

• Edge e4 connect vertices a and d.

• Edge e6 connect vertices e and e.

Page 17: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

• The degree of a vertex in an undirected

graph is the number of edges incident with

it, except that a loop at a vertex contributes

twice to the degree of that vertex.

• The degree of the vertex v is denoted by

deg(v).

Page 18: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

18

What are the degrees of the vertices in the following graph?

• ••

• •

b

a

c

f e

d

g

deg(a) =

deg(b) =

deg(c) =

deg(d) =

deg(e) =

deg(f) =

deg(g) =

2

4

4

3

1

4

0Vertex of degree zero is called isolated

Page 19: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

19

Theorem:Suppose the vertices of graph G are v1, v2, …,

vn, where n is a non-negative integer, then the total degree of G

=deg(v1) + deg(v2) + …. + deg(vn)

= 2 (the number of edges of G).

Page 20: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Total number of edges: 4 Total degree: 1 + 1 + 1 + 5 = 8. Handshaking theorem: 2 x 4 = 8.

Page 21: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

21

How many edges are there in a graph with seven vertices each of degree four?• The sum of the degrees of the vertices is

4x7 = 28.

2e = 28

e = 14.

Page 22: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Three methods1.Adjacency lists2.Adjacency matrices3.Incidence matrices

Page 23: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Adjacency lists

Vertex Adjacent Verticesa b,c,eb ac a,d,ed c,ee a,c,d

b

a c

deA simple graph

UNABLE TO REPRESENT MULTIPLE-EDGES.

Page 24: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Initial vertex Terminal verticesa b, c, d, eb b, dc a, c, ede b, c, d

A directed graph

Page 25: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Adjacency matrices

Suppose that G=(V, E) is a simple graph where |V|=n. Suppose that the vertices of G are listed arbitrary as v1,v2,..., vn. The adjacency matrix A of G is a n×n zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its entry when they are not adjacent.

1 if { , ) is an edge of G

0 otherwise

i j

ij

v va

Page 26: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

0 1 1 1

1 0 1 0

1 1 0 0

1 0 0 0

a b

c d

G Adjacency matrix for G

Page 27: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Representing multigraph or pseudograph

Page 28: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

0 1 0 0 1

0 1 0 0 0

1 0 0 1 0

0 0 1 0 1

0 0 0 0 0

a b c d ea

b

c

d

e

Adjacency Matrix

Page 29: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Incidence Matrices

Let G=(V, E) be an undirected graph. Suppose

that v1, v2, ..., vn are the vertices and e1, e2, ...,

em are the edges G. The incidence matrix of G

is a nx m matrix M=[mij], where

1 when edge is incident with ,

0 otherwise

j i

ij

e vm

Page 30: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

1 2 3 4 5 6

1

2

3

4

5

1 1 0 0 0 0

0 0 1 1 0 1

0 0 0 0 1 1

1 0 1 0 0 0

0 1 0 1 1 0

e e e e e e

v

v

v

v

v

Incidence Matrix

Page 31: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition

Let n be a nonnegative integer and G a

directed multigraph. A path of length n from u

to v in G is a sequence of edges e1, e2, ..., en

of G such that f(e1)=(x0, x1), f(e2)=(x1, x2),

f(en)=(xn-1, xn), where x0=u and xn=v.

Page 32: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

DefinitionWhen there are non multiple edges in the

directed graph, this path is denoted by its

vertex sequence x0, x1, x2, ..., xn.

A path of length greater than zero that begins

and ends at the same vertex is called a circuit

or cycle.

A path or circuit is simple if it does not contain

the same edge more than once.

Page 33: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

a, d, c, f, e is a simple path of length 4 since {a, d}, {d, c}, {c, f}, and {f, e} are all edges and no repeated edge.b, c, f, e, b is a circuit of length 4 since this path begins and ends at b.The path a, b, e, d, a, b is of length 5, is not simple since it contains the edge {a, b} twice.Is a, d, e, a, b a simple path?

Page 34: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Paths from v0 to v

7

1. v0 v

1 v

2 v

5 v

7

2. v0 v

1 v

4 v

5 v

4 v

5 v

7

3. v0 v

3 v

4 v

6 v

7

Which path(s) is (are) simple?

Page 35: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements
Page 36: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

DefinitionAn undirected graph is called connected if

there is a path between every pair of distinct vertices of the graph.

G is connected, whereas H is not.

Page 37: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Theorem

There is a simple path between every pair of distinct

vertices of a connected undirected graph.

Page 38: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

DefinitionA directed graph is strongly connected if there

is a path from a to b and from b to a whenever a and b are vertices in the graph.

DefinitionA directed graph is weakly connected if there

is a path between any two vertices in the underlying undirected graph.

Page 39: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

G is strongly connected because there is a path between any two vertices in this directed graph.

The graph H is not strongly connected. There is no directed path from a to b in this graph. H is weakly connected since there is a path between any two vertices in the underlying undirected graph of H.

Page 40: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Questions

Can we travel along the edges of graph

starting at a vertex and returning to it by

traversing each edge of the graph exactly

once?

Can we travel along the edges of a graph

starting at a vertex and returning to it while

visiting each vertex of the graph exactly

once?

Page 41: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition

An Euler circuit in a graph G is a simple circuit

containing every edge of G.

An Euler path in G is a simple path containing

every edge in G.

Note: Both in Euler path and Euler circuit, each edge cannot be repeated more than once.

If a graph has Euler circuit then it must has Euler path, the opposite could be false.

Page 42: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Example

Page 43: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

• Theorem 1

• A connected multigraph has an Euler circuit if

and only if each of its vertices has even degree.

• Theorem 2

• A connected multigraph has an Euler path but

not an Euler circuit if and only if it has exactly

two vertices of odd degree.

Page 44: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

For graph G1, the degree for each vertex in this graph is even, hence this graph contain Euler circuit.

For graph G2, the degree for vertex e, a are odd, so there is no Euler circuit.

G1 G2

Page 45: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

G1 contains exactly two vertices of odd degree, b and d. Hence it has an Euler path that must have b and d as its end points. E.g.:b, c, d, a, b, d.

G2 also contains exactly two vertices of odd degree, d and b. One of the Euler path is b, a, g, b, c, g, f, c, f, e, d.

Page 46: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Definition

• A path x0, x1, ..., xn-1, xn in the graph G = (V,

E) is called a Hamilton path if V={x0, x1, ...,

xn-1, xn} and xixj for 0 ijn

• A circuit x0, x1, ..., xn-1, xn , x0(with n > 1) in a

graph G = (V,E) is called a Hamilton circuit

◦if x0, x1, ..., xn-1 Hamilton path.

Page 47: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

Graph G1 has a Hamilton circuit: a, b, c, d, e, a.

There is no Hamilton circuit in G2 because edge (a, b) will be always use twice. E.g.: d, c, b, a, b, d. G2 has Hamilton path, a, b, c, d.

Page 48: Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements

• A graph with a vertex of degree 1 cannot

have a Hamilton circuit.

• If each vertex in a graph is adjacent to

every other vertex there is always a

Hamilton circuit.