Tải bản đầy đủ (.pdf) (69 trang)

Giáo trình bài tập dsp chapter6 student 19072015

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (836.52 KB, 69 trang )

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Chapter 9
More About Graphs
Discrete Structures for Computing on December 25, 2014

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

Huynh Tuong Nguyen, Tran Vinh Tan
Faculty of Computer Science and Engineering
University of Technology - VNUHCM


9.1


Acknowledgement

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity

Some slides about Euler and Hamilton circuits are created by
Chung Ki-hong and Hur Joon-seok from KAIST.

Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem


Planar Graphs
Graph Coloring

9.2


Contents

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

1 Connectivity

Paths and Circuits
2 Euler and Hamilton Paths

Euler Paths and Circuits
Hamilton Paths and Circuits

Contents
Connectivity
Paths and Circuits

3 Shortest Path Problem

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm

Ford’s algorithm
Traveling Salesman Problem

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs

4 Planar Graphs

Graph Coloring

5 Graph Coloring

9.3


More About Graphs

Paths and Circuits
a


b

c

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents

d

e

f

Connectivity
Paths and Circuits

Euler and Hamilton
Paths

Simple path of length 4

Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem

a


b

c

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

d

e

f

Circuit of length 4
9.4


More About Graphs

Path and Circuits

Huynh Tuong Nguyen,
Tran Vinh Tan


Definition (in undirected graph)
• Path (đường đi) of length n from u to v: a sequence of n

edges {x0 , x1 }, {x1 , x2 }, . . . , {xn−1 , xn }, where x0 = u and
xn = v.
• A path is a circuit (chu trình) if it begins and ends at the

same vertex, u = v.

Contents
Connectivity
Paths and Circuits

• A path or circuit is simple (đơn) if it does not contain the

same edge more than once.

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem

a

b

c


a

b

c

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

d

e
Simple path

f

d

e

f

Not simple path

9.5


Path and Circuits

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity

Definition (in directed graphs)

Path is a sequence of (x0 , x1 ), (x1 , x2 ), . . . , (xn−1 , xn ), where
x0 = u and xn = v.

Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm

Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.6


More About Graphs

Connectedness in Undirected Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Definition
• An undirected graph is called connected (liên thông ) if there

is a path between every pair of distinct vertices of the graph.
• There is a simple path between every pair of distinct vertices

of a connected undirected graph.

Contents
Connectivity
Paths and Circuits

d

e


b

Euler and Hamilton
Paths

f

Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

a

c

h

g

Planar Graphs
Graph Coloring

Connected graph

Disconnected graph
Connected components (thành phần liên thông )
9.7


More About Graphs

How Connected is a Graph?

Huynh Tuong Nguyen,
Tran Vinh Tan

d

a

f

g

Contents
Connectivity
Paths and Circuits

c

bb

e


Euler and Hamilton
Paths

h

Euler Paths and Circuits
Hamilton Paths and Circuits

Definition

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm

• b is a cut vertex (đỉnh cắt) or articulation point (điểm khớp).

What else?
• {a, b} is a cut edge (cạnh cắt) or bridge (cầu). What else?

Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.8


More About Graphs


How Connected is a Graph?
b

d

Huynh Tuong Nguyen,
Tran Vinh Tan

g
Contents

a

e

Connectivity
Paths and Circuits

Euler and Hamilton
Paths

Definition
• This graph don’t have cut vertices: nonseparable graph (đồ

thị không thể phân tách)

Euler Paths and Circuits
Hamilton Paths and Circuits


Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm

• The vertex cut is {c, f }, so the minimum number of vertices

in a vertex cut, vertex connectivity (liên thông đỉnh)
κ(G) = 2.

Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

• The edge cut is {{b, c}, {a, f }, {f, g}}, the minimum number

of edges in an edge cut, edge connectivity (liên thông cạnh)
λ(G) = 3.
9.9


Applications of Vertex and Edge Connectivity

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan


• Reliability of networks
• Minimum number of routers that disconnect the network
• Minimum number of fiber optic links that can be down to
disconnect the network

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits

• Highway network
• Minimum number of intersections that can be closed
• Minimum number of roads that can be closed

Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.10



More About Graphs

Connectedness in Directed Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Definition
• An directed graph is strongly connected (liên thông mạnh) if

there is a path between any two vertices in the graph (for
both directions).
• An directed graph is weakly connected (liên thông yếu) if

Contents

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

Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits

a


b

a

b

Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm

c

c

Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs

e

d
Strongly connected

e

Graph Coloring


d
Weakly connected
9.11


More About Graphs

Applications

Huynh Tuong Nguyen,
Tran Vinh Tan

Example

Determine whether the graphs below are isomorphic.
u1

v1
Contents

u6

u2

v6

v2

Connectivity

Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem

u5

u3

v5

v3

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

u4
G

v4
H

Planar Graphs

Graph Coloring

Solution

H has a simple circuit of length three, not G.
9.12


More About Graphs

Applications

Huynh Tuong Nguyen,
Tran Vinh Tan

Example

Determine whether the graphs below are isomorphic.
u2

v2
Contents
Connectivity
Paths and Circuits

u1

u3

v1


v3

Euler and Hamilton
Paths
Euler Paths and Circuits

u5

u4

v5

v4

Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm

Solution

Both graphs have the same vertices, edges, degrees, circuits. They
may be isomorphic.
To find a possible isomorphism, we can follow paths that go
through all vertices so that the corresponding vertices in the two
graphs have the same degrees.

Floyd-Warshall Algorithm

Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.13


The Famous Problem of Seven Bridges of K¨
onigsberg

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm


• Is there a route that a person crosses all the seven bridges

once?

Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.14


Euler Solution

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits


Shortest Path Problem

• Euler gave the solution: It is not possible to cross all the

bridges exactly once.

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.15


What is Euler Path and Circuit?

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

• Euler Path (đường đi Euler ) is a path in the graph that

passes each edge only once.
The problem of Seven Bridges of K¨onigsberg can be also
stated: Does Euler Path exist in the graph?


Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits

• Euler Circuit (chu trình Euler ) is a path in the graph that

passes each edge only once and return back to its original
position.
From Definition, Euler Circuit is a subset of Euler Path.

Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.16



More About Graphs

Examples of Euler Path and Circuit

Huynh Tuong Nguyen,
Tran Vinh Tan

4

3

D

C
Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

1

2

A

B


Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs

Euler Circuit

Euler Path

Graph Coloring

9.17


Conditions for Existence

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

In a connected multigraph,
• Euler Circuit existence: no odd-degree nodes exist in the

graph.

• Euler Path existence: 2 or no odd-degree nodes exist in the

graph.

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.18


Back to the Seven Bridges Problem

More About Graphs


Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

• Four vertices of odd degree
• No Euler circuit → cannot cross each bridge exactly once,

and return to starting point

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

• No Euler path, either

Planar Graphs
Graph Coloring

9.19



Searching Euler Circuits and Paths – Fleury’s Algorithm

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

• Choose a random vertex (if circuit) or an odd degree vertex

(if path)
• Pick an edge joined to another vertex so that it is not a cut

edge unless there is no alternative

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

• Remove the chosen edge. The above procedure is repeated

until all edges are covered.

Shortest Path Problem

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.20


Searching Euler Circuits and Paths – Hierholzer’s Algorithm

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents

• Choose a starting vertex and find a circuit
• As long as there exists a vertex v that belongs to the current

tour but that has adjacent edges not part of the tour, start
another circuit from v

Connectivity
Paths and Circuits


Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem

More efficient algorithm, O(n).

Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.21


More About Graphs

Exercise

Huynh Tuong Nguyen,
Tran Vinh Tan

Example


Are these following graph Euler path (circuit)? If yes, find one.
g

a

f

e
Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits

c

b

Hamilton Paths and Circuits

d
b

a

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm

Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs

f

c

g

e

d

Graph Coloring

9.22


Traveling Salesman Problem

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan

Contents
Connectivity

Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm

Is there the possible tour that visits each city exactly once?

Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.23


What Is A Hamilton Circuit?

More About Graphs

Huynh Tuong Nguyen,
Tran Vinh Tan


Definition

The circuit that visit each vertex in a graph once

Contents
Connectivity
Paths and Circuits

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem

Planar Graphs
Graph Coloring

9.24


More About Graphs

Rules of Hamilton Circuits


Huynh Tuong Nguyen,
Tran Vinh Tan

deg(v) = 2 for ∀v in Hamilton circuit!
Rule 1 if deg(v) = 2, both edge must be used.

Contents
Connectivity
Paths and Circuits

v

Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits

Rule 2 No subcircuit (chu trình con) can be formed.

Shortest Path Problem
Dijkstra’s Algorithm

Rule 3 Once two edges at a vertex v is determined, all
other edges incident at v must be removed.
v

Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Traveling Salesman Problem


Planar Graphs
Graph Coloring

9.25


×