25
JC Liu MACM101 Discrete Mathematics I 1 Lecture 13: Shortest Path and Graph Coloring Shortest Path Problems Graph Coloring

Lecture 13: Shortest Path and Graph Coloring

  • Upload
    gayle

  • View
    62

  • Download
    2

Embed Size (px)

DESCRIPTION

Lecture 13: Shortest Path and Graph Coloring. Shortest Path Problems Graph Coloring. 13.1. Shortest Path Problems. A weighted graph : Is a graph in which a number called the weight is assigned to each edge. The weight of a path : Is the sum of weights of the edges in the path. - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 1

Lecture 13: Shortest Path and Graph Coloring

Shortest Path Problems Graph Coloring

Page 2: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 2

13.1. Shortest Path Problems

A weighted graph:• Is a graph in which a number called the weight is

assigned to each edge.

The weight of a path:• Is the sum of weights of the edges in the path.

The shortest path from u to v:• Is the path of the smallest weight between the two

vertices.

• The weight of that path is called the distance between them.

Page 3: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 3

13.1. Shortest Path Problems

Examples:

• Weight of the edge on A and B is 3.

• Weight of the path A, C, D, F is 4 + 2 + 5 = 11.

• The shortest path between A and D is A, B, D.

• The distance between A and D is 4.

Page 4: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 4

13.1. Shortest Path Problems

Examples:• The weight can be mileage, fares, response time, etc.

Page 5: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 5

13.1. Shortest Path Problems

Rationale• Given shortest path Pa-b from vertex a to b, and Pa-b

passes vertex c

• Path Pa-c (a subpath of Pa-b) is a shortest path from vertex a to c

• Length of Pa-c <= Length of Pa-b

Page 6: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 6

13.1. Shortest Path Problems

Dijkstra’s Algorithm: Dijkstra (1930-2002)• Is a popular algorithm for finding shortest path.

• Applications: Internet routing.

Page 7: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 7

13.1. Shortest Path Problems

Examples:• Use Dijkstra’s algorithm to find the length of the shortest

path between the vertices a and z in the following weighted graph.

• Solution:• At each iteration of the algorithm, the vertices of the set S is

circled. The algorithm terminates when z is circled.

Page 8: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 8

13.1. Shortest Path Problems

13 (a, c, b, d, e)

Page 9: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 9

13.1. Shortest Path Problems

Question:• What about longest path ?

Page 10: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 10

13.1. Shortest Path Problems

Question:• What about negative weight ?

Page 11: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 11

13.1. Shortest Path Problems

Question:• In the algorithm, weight is additive, i.e., min w1+w2+w3…

• How about multiplicative, i.e., min w1*w2*w3…

Page 12: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 12

13.1. Shortest Path Problems

Question:• In the algorithm, weight is additive, i.e., min w1+w2+w3…

• How about multiplicative, i.e., min w1*w2*w3…

Solution:• Min w1*w2*w3… is equivalent to min (log w1*w2*w3…)

Page 13: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 13

Page 14: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 14

Page 15: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 15

(A)

(B)

(C)

(D)

(E)

13.1. Shortest Path Problems

Important shortest path problem:• The traveling salesman problem.

• A traveling salesman wants to visit each of n cities exactly once and return to his starting point.

• In which order should he visit these cities to travel the minimum total distance?

Page 16: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 16

13.1. Shortest Path Problems

• Solution:

• Find all possible Hamilton circuits.

• Assume that the salesman starts in Detroit.

• Then we need to examine (n-1)!/2 different circuits.

• Calculate the length of each circuit.

• Select one with minimum total length.

• A-B-C-D-E-A (or its reverse): 458 km.

Route Total distance (km)

A-B-C-D-E-A

A-B-C-E-D-A

A-B-D-C-E-A

A-B-D-E-C-A

A-B-E-C-D-A

A-B-E-D-C-A

458

588

516

610

540

504

Route Total distance (km)

A-E-B-C-D-A

A-E-B-D-C-A

A-E-C-B-D-A

A-E-D-B-C-A

A-D-B-E-C-A

A-D-E-B-C-A

576

598

682

646

728

670

Page 17: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 17

13.2. Graph Coloring

A coloring of a graph:• Is the assignment of a color to each vertex of the

graph so that adjacent vertices have different colors.

• For most graphs, we can use fewer colors than the number of vertices in the graph

The chromatic number of a graph:• Is the least number of colors needed for coloring the

graph.

Page 18: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 18

13.2. Graph Coloring

Examples:• When a cycle Cn has an even number of vertices, it

can be colored using 2 colors.

• When a cycle Cn has an odd number of vertices, it can be colored using 3 colors.

Page 19: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 19

13.2. Graph Coloring

Examples:• Coloring for the complete graph Kn –

• How many ?

Page 20: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 20

13.2. Graph Coloring

Examples:• The complete graph Kn can be colored with n colors.

• No smaller number of colors is possible since every two vertices of this graph are adjacent.

Page 21: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 21

13.2. Graph Coloring

Examples:• The complete bipartite graph Km,n can be colored with

2 colors.

• i.e. color the set of m vertices with one color and the set of n vertices with a second color.

• e.g. A coloring of K3,4.

Page 22: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 22

13.2. Graph Coloring

• The 4-color problem Chromatic number of a

map (planar graph) ≤ 4

• 1850 – asked by a De Morgan’s student

• 1976 – proved by K. Appel and W. Haken using a computer

Page 23: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 23

13.2. Graph Coloring

Applications of graph coloring:• Scheduling final exams.

• How can the final exams can be scheduled so that no student has two exams at the same time?

• Solution:

• Use a graph model with vertices representing courses and with an edge between two vertices if there is a student taking both courses.

• Each time slot of a final exam is represented by a different color.

Page 24: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 24

13.2. Graph Coloring

• Solution (continued):

• Suppose there are 7 finals with common students in courses {(1,2), (1,3), … } as represented by the graph. So, we need four color or time slots.

Page 25: Lecture 13:  Shortest Path  and Graph Coloring

JC Liu MACM101 Discrete Mathematics I 25

13.3. Further Readings

Shortest Path Problems : Section 8.6. Graph Coloring : Section 8.8.