<<

CIT 596 – Theory of Computation 1

Graphs and Digraphs

A graph = (V (G),(G)) consists of two finite sets:

• V (G), the vertex of the graph, often denoted by just V , which is nonempty set of elements called vertices, and

• E(G), the edge set of the graph, often denoted by just E, which is a possibly empty set of elements called edges, such that each edge e in E is assigned an unordered pair (, v) of vertices, called the end vertices of e. Sometimes, it is convenient to denote (u, v) by simply uv, or equivalently, vu.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 2

Graphs and Digraphs

Consider the graph G = (V,E) such that

V = {a,,c,d,e} and E = {e1, e2, e3, e4, e5, e6, e7, e8}, where e1 ←→ (a,b) e2 ←→ (b, c)

e3 ←→ (c, c) e4 ←→ (c, d)

e5 ←→ (b,d) e6 ←→ (d, e)

e7 ←→ (b, e) e8 ←→ (b, e)

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 3

Graphs and Digraphs

A graph is often represented by a diagram in which vertices are drawn as circles and edges as line or curve segments joining the circles repre- senting the end vertices of the edge.

e8 e1 a b e

e7

e2 e6 e5

e3 c d e4

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 4

Graphs and Digraphs

Vertices are also called points, nodes, or just dots.

If e is an edge with end vertices u and v then e is said to join u and v.

Note that the definition of a graph allows the possibility of the edge e having idetical end vertices, .e., it is possible to have a vertex u joined to itself by an edge — such an edge is called a .

If two (or more) edges have the same end vertices then edges are called parallel.

A graph is called simple is it has no loops and no parallel edges.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 5

Graphs and Digraphs

For an example of a simple graph, consider the graph G = (V,E) such that

V = {a,b,c,d} and E = {e1, e2, e3, e4}, where e1 ←→ (a,b) e2 ←→ (a, c)

e3 ←→ (b, c) e4 ←→ (c, d)

Some authors use the term for graphs with loops and parallel edges, and reserve the term graph for simple graphs only. Since we will deal with graphs with loops very often, it is more convenient not to make this distinction.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 6

Graphs and Digraphs

A pictorial representation of the simple graph G in the previous slide:

e1 a b

e2 e3

c

e4

d

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 7

Graphs and Digraphs

The number of vertices in G is called the order of G.

The number of edges in G is called the size of G.

Two vertices u and v of a graph G are said to be adjacent if uv ∈ E(G).

If uv 6∈ E(G) then we say that u and v are non-adjacent vertices.

An edge e of a graph G is said to be incident with or incident to the vertex v if v is an end vertex of e. In this case, we also say that v is incident with or incident to e.

Two edges e and which are incident with a common vertex v are said to be adjacent.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 8

Graphs and Digraphs

Let v be a vertex of the graph G. The d(v) of v is the number of edges of G incident to v, counting each loop twice, i.e., it is the number of times v is an end vertex of an edge.

b e

a

c d

For example, d(a) = 1, d(b) = 3, d(c) = 3, d(d) = 3, and d(e) = 4 in the graph above.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 9

Graphs and Digraphs

The First Theorem of . For any graph G with ne edges and nv vertices v1,...,vnv, we have that

nv d(vi) = 2 · ne. i=1 Check by yourself:

b e

a

c d

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 10

Graphs and Digraphs

A walk in a graph G is a finite sequence

W = v0e1v1e2v2 ...vk−1ekvk whose terms are alternately vertices and edges such that, for 1 ≤ i ≤ , the edge ei has end vertices vi−1 and vi.

We say that the above walk is a v0–vk walk or a walk from v0 to vk.

The k, the number of edges of the walk, is called the length of .

A trivial walk is one containing no edges.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 11

Graphs and Digraphs

The sequence c e2 b e8 f e6 c e3 d e4 e e4 d is a c–d walk of length 6 in the graph below.

b d e e1 2 e3

a e8 c e4

e7 e e6 5

f e

In a simple graph, a walk is determined by the sequence of vertices only: cbfcded.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 12

Graphs and Digraphs

Given two vertices u and v of a graph G, a u–v walk is called closed or open depending on whether u = v or u 6= v.

If the edges e1, e2,...,ek of the walk v0e1v1e2v2 ...vk−1ekvk are dis- tinct then W is called a trail.

If the vertices v0, v1,...,vk of the walk v0e1v1e2v2 ...vk−1ekvk are distinct then W is called a path.

For the graph in the previous slide, fbcdec is a f–c trail, but not a path!

The sequence fbcde is a f–e path.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 13

Graphs and Digraphs

A vertex u is said to be connected to a vertex v in a graph G if there is a path in G from u to v.

A graph G is connected if every two vertices of G are connected; oth- erwise, G is disconnected.

M b d b

a c a c

Connected Disconnected

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 14

Graphs and Digraphs

A nontrivial closed trail C = v1v2 ...vnv1 in a graph G is called a if the vertices v2 ...vn are all distinct.

A cycle of length k, i.e., a cycle with k edges, is called a k-cycle. For example, bcfb is a 3-cycle in the graph below:

b d e e1 2 e3

a e8 c e4

e7 e e6 5

f e

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 15

Graphs and Digraphs

A graph G is said to be acyclic if it contains no cycles. A graph G is called a if it is connected and acyclic.

a

b c d

e

The vertices of degree (at most) 1 in a tree are called the leaves of the tree.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 16

Graphs and Digraphs

A directed graph (or simply digraph) D = (V (D),A(D)) consists of two finite sets:

• V (D), the vertex set of the digraph, often denoted by just V , which is a nonempty set of elements called vertices, and

• A(D), the arc set of the digraph, often denoted by just A, which is a possibly empty set of elements called arcs, such that each arc a in A is assigned a (ordered) pair (u, v) of vertices. If a is an arc in D with associated of vertices (u, v), then a is said to join u to v, u is called the initial vertex of a, and v is called the terminal vertex of a.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 17

Graphs and Digraphs

For example, consider the digraph D = (V (D),A(D)) such that V (D) = {a,b,c,d,e} and A(D) = {e1, e2, e3, e4, e5, e6}, such that e1 ←→ (b, c), e2 ←→ (d, c), e3 ←→ (c, d), e3 ←→ (d, e), e4 ←→ (e, d), and e6 ←→ (e, e).

e6

a b e

e1 e5 e4

e2

c d

e3

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 18

Graphs and Digraphs

Let D be a digraph. Then a directed walk in D is a finite sequence

W = v0a1v1 ...akvk, whose terms are alternately vertices and arcs such that for 1 ≤ i ≤ k, the initial vertex of the arc ai is vi−1 and its terminal vertex is vi. The number k of arcs is the length of W .

The walk W given in the definition above is said to be a v0–vk directed walk or a directed walk from v0 to vk.

There are similar definitions for directed trails, directed paths, and di- rected cycles.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 19

Graphs and Digraphs

For example, consider the digraph D below:

e6

a b e

e1 e5 e4

e2

c d

e3

The sequence b e1 c e3 d e4 e is a b–e directed walk, a b–e directed trail, and a b–e directed path in D.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 20

Graphs and Digraphs

A vertex v of the digraph D is said to be reachable from a vertex u if there is a directed path from u to v.

Given any digraph D = (V (D),A(D)), we can obtain a graph G = (V (G),E(G)) from D as follows: Let V (G) = V (D) and E(G) = {e ←→ (a,b) | (a,b) ∈ A(D)}. The graph G is the underlying graph of D.

A digraph D is said to be weakly connected (or simply connected) if its underlying graph is connected. A digraph D is said to be strongly connected (or diconnected) if for any pair of vertices u and v in D there is a directed path from u to v.

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 21

Graphs and Digraphs

e6 e6

a b e a b e

e1 e5 e4 e1 e5 e4

e2 e2

c d c d

e3 e3

A digraph Its underlying graph

Is the above directed graph connected? If so, is it strongly connected?

°c Marcelo Siqueira — Spring 2005 CIT 596 – Theory of Computation 22

Graphs and Digraphs

Let v be a vertex in a digraph D. The indegree id(v) of v is the number of arcs of D that have v as the terminal vertex, i.e., the number of arcs that “go to” to v. Similarly, the outdegree od(v) of v is the number of arcs of D that have v as the initial vertex, i.e., the number of arcs that “go out” of v.

The First Theorem of Digraph Theory. Let D be a digraph with n vertices and arcs. If v1,...,vn is the set of vertices of D, then we have that n n X id(vi) = X od(vi) = q. i=1 i=1

Can you figure out the proof for this one?

°c Marcelo Siqueira — Spring 2005