introduction to graph theory instructor: dr. chaudhary department of computer science millersville...

28
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1

Upload: brittney-mothershead

Post on 14-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Introduction to Graph Theory

Instructor: Dr. ChaudharyDepartment of Computer ScienceMillersville University

Reading Assignment Chapter 1

Topics

Definition of a Graph

Walks and Paths

Degree of Vertecies

Minimum Spanning Tree (MST)

Relationship Between Degrees and Vertices

Euler's Path Problem

Traveling Salesman’s Problem

Definition of a Graph

A graph G = (V, E) is an ordered pair, where V is a nonempty finite set, and E is a binary relation on V. Members of V are called vertices and members of E are called edges. An edge connects two vertices.

v8

v6v9

v7

v1

v5

v3

v2

v4 (v3, v4) and (v2, v2) areedges

Fig 1: An undirected graph

Fig 2: A directed weighted graph

D

S

D

C

F 10

5

7

4

2

6

8

Walks and Paths

A sequence of edges (vi, vj), (vj, vk), …, (vm, vn) is said to be a walk from vi to vn.

Walk

A path is a walk in which no edges are repeated.Path

(v1, v5), (v5, v2), (v2, v1), (v1, v2), and (v2, v3) is a walk from v1 to v3.

(v1, v5), (v5, v2), (v2, v2), and (v2, v3) is a path from v1 to v3.

(v1, v5), (v5, v2), and (v2, v3) is a simple path from v1 to v3.

(v2, v2) is a loop.

v8

v6v9

v7

v1

v5

v3

v2

v4

Degree of a Vertex

The degree of a vertex v, denoted by deg(v), is simply the number of times an edge of G meets v. This is not quite the same as the number of edges that are incident with v, since we must count any loops at v twice when determining the degree of v.

Degree

deg(v1) = 2, deg(v2) = 7, deg(v3) = 2deg(v4) = 1, deg(v5) = 2, deg(v6) = 4deg(v7) = 1, deg(v8) = 3, deg(v9) = 0

Referring to fig. 1

v8

v6v9

v7

v1

v5

v3

v2

v4

Relationship Between Degrees and Vertices

A connection between degrees of vertices in a graph and number of edges in a graph is expressed in the following theorem.

Theorem: If G(V, E) is a graph with V = {v1, v2, ..., vn}, then deg(v1) + deg(v2) + ... + deg(vn) = 2|E|.

That is, the sum of degrees of all vertices in a graph G is equal to twice the number of edges of G.

We observe that each edge that is not a loop is incident with exactly two vertices, and each loop is incident with same vertex twice. Hence, the number 2|E|.

Linear and Complete Graphs

If a graph G has vertices of degrees 2, 2, 2, 3, 3, 3, 4, 4, 5, and 6 then, according to the above theorem, the number of edges = 17. (2+2+2+3+3+3+4+4+5+6 = 34)There is no graph G with degrees of its vertices 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, and 6. Why?

A graph is called linear graph if there is a single edge between every pair of vertices.

A linear graph with n vertices has at most C(n, 2) edges. If a linear graph with C(n, 2) edges is called a complete graph.

A complete graph on 5 nodes.

A linear graph with n vertices has at most C(n, 2)

edges

If a linear graph with C(n, 2) edges is called a complete graph.

C(n, 2) means combination of n things taken 2 at a time.

2

)1(

)!2(!2

!)2,(

nn

n

nnC

Number of edges = 02

)11(1

2

)1(

nn

12

)12(2

2

)1(

nn

32

)13(3

2

)1(

nn

62

)14(4

2

)1(

nn

Number of edges =

Number of edges =

Number of edges =

A complete graph with 5 vertices

102

)15(5

2

)1(

nn

Exercise : Use mathematical induction to prove that a complete linear graph on n vertices has edges.

2

)1( nn

Spanning Trees

Example

Example 2: Spim’s Algorithm

Start at vertex a

http://www.cs.auckland.ac.nz/~jmor159/PLDS210/dijkstra.html

Example Continued

Example Continued

Path Length = 4 + 8 + 2 + 1 + 2 + 5 = 22

Euler's Path Problem

• Euler's Path (Konigsberg’s bridge problem)

Theorem: An undirected graph possesses an Eulerian path if and only if it is connected and has none or two vertices of odd degree.

A path in a graph is called Eulerian path if it traverses each edge in a graph exactly once.

http://mathforum.org/isaac/problems/bridges1.html

The people wondered whether or not one could walk around the city in a way that would involve crossing each bridge exactly once.

Euler’s Path Problem :Example – Page 1

b

a

c

d

ef

g

Since all vertices have even degrees, there is an Euler’s circuit in the graph.

Euler’s Path Problem :Example – Page 2

b

a

c

d

ef

g

b

a

c

d

ef

g

Euler’s Path Problem :Example – Page 3

b

a

c

d

ef

g1

2

3

4

5

67

8

9

10

The numbers indicate the order of traversal.

Traveling Salesman’s Problem

Theorem: A Hamiltonian path in a graph is a path that passes through every vertex in the graph.

Consider a salesperson who wants a tour of n cities which starts and ends at the same city and includes visiting each of the remaining n - 1 cities once and only once, subject to the condition that such a tour is also of minimum length.

The problem is no more than finding a Hamiltonian circuit in a weighted graph. But no efficient algorithm has been discovered to solve this problem.

http://www.tsp.gatech.eduPlease visit the site

Traveling Salesman Problem: Nearest Neighbor Algorithm

1. Start with an arbitrary chosen vertex, and find the vertex that is closest to the starting vertex to form an initial path of one edge. This path will be augmented in a vertex-by-vertex manner as described in step 2.

2. Let x be the latest vertex that was added to the path. Among all vertices that are not in the path, pick the one that is closest to x, and add to the path the edge connecting x and this vertex. Repeat this step 2 until all vertices are included in the path.

3. Form a circuit by adding the edge connecting the starting vertex and the vertex added.

Example – Page 1

7 10

11

9

1412

5 6813

a

b c

de

1Start from vertex a.

Example – Page 2

7

a

b c

de

2

Example – Page 3

7

6

a

b c

de

3

Example – Page 4

7

6

a

b c

de

4

8

Example – Page 5

7

6

a

b c

de

5

8

5

Example – Page 6

7

6

a

b c

de

6

14

8

Total Path Length = 7 + 6 + 8 + 5 + 14 = 40

5

A Better Solution

7 109

5 6

b c

de

a

Total Path Length = 7 + 6 + 9 + 5 + 10 = 37

Four-color Problem

http://www.math.gatech.edu/~thomas/FC/fourcolor.html

Is it true that any map can be colored using four colors in such a way that adjacent regions (i.e. those sharing a common boundary segment, not just a point) receive different colors?The answer is yes. Please read the history by visiting the following web sites.