Graphs - - PowerPoint PPT Presentation

graphs
SMART_READER_LITE
LIVE PREVIEW

Graphs - - PowerPoint PPT Presentation

Graphs (04/11/48) Graphs A edge


slide-1
SLIDE 1

Graphs

สมชาย ประสิทธิ์จูตระกูล ภาควิชาวิศวกรรมคอมพิวเตอร จุฬาลงกรณมหาวิทยาลัย

(04/11/48)

slide-2
SLIDE 2

Graphs

A D C B

Königsberg Bridge Problem 1736: Leonhard Euler

edge vertex B A C D

slide-3
SLIDE 3

Applications

1 4 5 2 3

+

slide-4
SLIDE 4

Applications

a b c d e

ก ข ค ง

article adj. adj. noun verb noun a b c z d e s

20 5 19 4 3 12 6 5 10 10 9 9

slide-5
SLIDE 5

Applications

\ 2110211 2110200 handout quiz java quiz Math4 w1.doc q1.txt q2.txt Demo.java q1.doc GF gf.nb coef.nb

RAM L1 L2 PLA ALU RAM L1 L2 PLA ALU

slide-6
SLIDE 6

Applications

/3 /3 ×2 ×2 ×2 1 2 4 8 /3 /3 ×2 ×2 16 /3 /3 /3 ×2 10 5

slide-7
SLIDE 7

Undirected & Directed Graphs

A A B B C C D D Digraph

slide-8
SLIDE 8

Weighted Graphs

A A B B C C D D 2 1 3 5 9 –1 2 2 1 3 5 9 –1 2

slide-9
SLIDE 9

Multigraphs & Simple graphs

self-loop parallel edges Multigraph Multigraph A graph that has neither self-loops nor parallel edges is called a simple graph.

slide-10
SLIDE 10

Complete Graphs

complete graph ที่มี v vertices มี v(v – 1)/2 edges

slide-11
SLIDE 11

Connected Graphs

1 component (connected graph) 2 components

  • A connected (undirected) graph with v vertices has at least v – 1 edges
  • A simple graph with v vertices and C(v – 1,2) edges must be connected
slide-12
SLIDE 12

Degree

  • e2 is incident on v2
  • v1 is adjacent to v2
  • degree of v3 is 3

v3 v2 v4 v1 e1 e2 e6 e3 e4 e5 v5

The sum of the degrees of all vertices in an undirected graph is twice the number of edges in the graph. The number of vertices of odd degree in an undirected graph is always even.

slide-13
SLIDE 13

แบบฝกหัด

  • What is the minimum number of cables needed to

connect 5 computers so that all of them can exchange information ?

  • Can it be concluded that a simple graph with 5 vertices

and 6 edges is connected ?

  • Must the number of people ever born who had (have) an
  • dd number of brothers and sisters be even ?
  • What is the largest possible number of vertices in a graph

with 19 edges and all vertices of degree at least 3 ?

  • Is it possible that each person at a party know 5 other

persons in the party ?

slide-14
SLIDE 14

Paths & Cycles

A path or circuit is simple if it passes through a vertex at most one time.

slide-15
SLIDE 15

Euler Paths & Circuits

  • An Euler circuit in a graph is a circuit that

traverses all the edges in the graph once.

  • An Euler path in a graph is a path that traverses

all the edges in the graph once.

  • An undirected multigraph has an Euler circuit if

and only if it is connected and has all vertices of even degree.

  • An undirected multigraph has an Euler path, but

not Euler circuit, if and only if it is connected and has exactly two vertices of odd degree.

slide-16
SLIDE 16

Euler Paths & Circuits

slide-17
SLIDE 17

Hamilton Paths & Circuits

  • A Hamilton circuit in a graph is a (simple)

circuit that visits each vertex in the graph

  • nce.
  • A Hamilton path in a graph is a (simple)

path that visits each vertex in the graph

  • nce
slide-18
SLIDE 18

Traveling Salesperson Problem

  • A salesman is required to visit a number of cities

during a trip. Given the distances between cities, in what order should he travel so as to visit every city precisely once and return home, with the minimum mileage traveled ?

slide-19
SLIDE 19

Trees

  • a acyclic connected graph
  • v vertices, v – 1 edges, no cycle
  • v vertices, v – 1 edges, connected
  • exactly one simple path connects each

pair of vertices

slide-20
SLIDE 20

Subgraphs

  • A subgraph is a subset of a graph's edges

(and associated vertices) that constitutes a graph

b c d a e b c d

slide-21
SLIDE 21

Terminology

slide-22
SLIDE 22

Planar Graphs

A graph is called planar if it can be drawn in the plane without any edges crossing.

Output Output 2V

  • 4V

x y z Output

slide-23
SLIDE 23

Homeomorphic Gaphs

Two graphs are called homeomorphic if one graph can be

  • btained from the other by the creation of edges in series or by

the merger of edges in series. A graph G is planar if and only if every graph that is homeographic to G is planar.

slide-24
SLIDE 24

Kuratowski Graphs

a b c d e g a e b c g d

|V| = 5, |E| = 10 |V| = 6, |E| = 9

K5 K3,3

slide-25
SLIDE 25

Kuratowski's Theorem

A graph is nonplanar if and only if it contains a subgraph homeomorphic to K5 or K3,3

slide-26
SLIDE 26

Graph Coloring

A coloring of a simple graph is the assignment of a color to each vertex of the graph so that no two adjacent vertices are assigned the same color.

ดํา ฟา แดง เขียว ขาว ดํา ฟา แดง ฟา ขาว ดํา ฟา แดง ฟา แดง

slide-27
SLIDE 27

Graph Coloring

1: P : = X + Y 2: X : = X * P 3: Q : = 1/ R 4: P : = R - Q 5: X : = R/ P 6: Y : = 0. 5 X Y P Q R X, 1 R, 2 Q, 1 P2, 3 P1, 3 Y, 2

slide-28
SLIDE 28

Four-Color Theorem

3 2 1 3 1 2 3 4

slide-29
SLIDE 29

Graph Representations

  • adjacency matrix
  • adjacency list

1 4 3 2 4 1

  • 2

2 3 3 2

0 1 2 3 4 0 - 4

  • 1
  • 1 -
  • 3
  • -2

2 -

  • 3

2 3 - 2

  • 4 -
  • 1

2 3 4 < (1,4), (3,1) > < (2,3), (4,-2) > < (3,3), (4,2) > < (1,2) > < >

slide-30
SLIDE 30

Graph Representations

slide-31
SLIDE 31

Basic Graph Algorithms

  • Breadth-First Search
  • Depth-First Search
  • Topological Sort
  • Strongly Connected Components
slide-32
SLIDE 32

Breadth-First Search

slide-33
SLIDE 33

BFS(G, s) for each vertex u ∈ V[G] - {s} do color[u] ← WHITE d[u] ← ∞ p[u] ← NIL color[s] ← GRAY d[s] ← 0 p[s] ← NIL Q ← Ø ENQUEUE(Q, s) while Q ≠ Ø do u ← DEQUEUE(Q) for each v ∈ Adj[u] do if color[v] = WHITE then color[v] ← GRAY d[v] ← d[u] + 1 p[v] ← u ENQUEUE(Q, v) color[u] ← BLACK

PRINT-PATH(G, s, v) if v = s then print s else if p[v] = NIL then "no path" else PRINT-PATH(G, s, p[v]) print v

slide-34
SLIDE 34

Shortest Path

slide-35
SLIDE 35

1/

u v w x y z

1/ 2/

u v w x y z

1/ 2/ 3/

u v w x y z

1/ 2/ 4/ 3/

u v w x y z

Depth-First Search

slide-36
SLIDE 36

1/ 2/ 4/5 3/6

u v w x y z

1/ 2/7 4/5 3/6

u v w x y z

1/ 2/7 4/5 3/6

u v w x y z

1/8 2/7 4/5 3/6

u v w x y z

1/ 2/ 4/ 3/

u v w x y z

1/ 2/ 4/5 3/

u v w x y z

slide-37
SLIDE 37

1/8 2/7 9/ 4/5 3/6 10/

u v w x y z

1/8 2/7 9/ 4/5 3/6 10/

u v w x y z

1/8 2/7 9/ 4/5 3/6 10/11

u v w x y z

1/8 2/7 9/12 4/5 3/6 10/11

u v w x y z

1/8 2/7 9/ 4/5 3/6

u v w x y z

1/8 2/7 9/ 4/5 3/6

u v w x y z

slide-38
SLIDE 38

DFS(G) for each vertex u ∈ V[G] do color[u] ← WHITE p[u] ← NIL time ← 0 for each vertex u ∈ V[G] do if color[u] = WHITE then DFS-VISIT(u) DFS-VISIT(u) color[u] ← GRAY d[u] time ← time + 1 for each v ∈ Adj[u] do if color[v] = WHITE then p[v] ← u DFS-VISIT(v) color[u] ← BLACK f [u] ← time ← time +1

tree edge (เจอขาว) back edge (เจอเทา) forward edge (เจอดํา d เรานอย) cross edge (เจอดํา d เรามาก)

slide-39
SLIDE 39
slide-40
SLIDE 40

Topological Sort

ทํา DFS ลําดับจากซายไปขวา จะเรียงตาม f จากมากไปนอย

slide-41
SLIDE 41

Strongly Connected Components

ทํา DFS(G) ทํา DFS(GT) โดยใหพิจารณา u เรียงตาม f จากมากไปนอย ที่หา ไดจาก DFS ครั้งแรก แตละตนในปาไมที่ไดคือ SCCs

DFS(G) for each vertex u ∈ V[G] do color[u] ← WHITE p[u] ← NIL time ← 0 for each vertex u ∈ V[G] do if color[u] = WHITE then DFS-VISIT(u)

slide-42
SLIDE 42

Hard Graph Problems

input

  • utput

clique partitioning

slide-43
SLIDE 43

Hard Graph Problems

input

  • utput

independent set vertex cover

slide-44
SLIDE 44

Hard Graph Problems

input

  • utput

vertex coloring edge coloring