Introduction to Graphs Historical Motivation Seven Bridges of K - - PowerPoint PPT Presentation

introduction to graphs historical motivation seven
SMART_READER_LITE
LIVE PREVIEW

Introduction to Graphs Historical Motivation Seven Bridges of K - - PowerPoint PPT Presentation

Introduction to Graphs Historical Motivation Seven Bridges of K onigsberg K onigsberg (now Kaliningrad, Russia) around 1735 Problem: Find a walk through the city that would cross each bridge once and only once. 3 / 22 Definitions Graph


slide-1
SLIDE 1

Introduction to Graphs

slide-2
SLIDE 2

Historical Motivation

slide-3
SLIDE 3

Seven Bridges of K¨

  • nigsberg

  • nigsberg (now Kaliningrad, Russia) around 1735

Problem: Find a walk through the city that would cross each bridge

  • nce and only once.

3 / 22

slide-4
SLIDE 4

Definitions

slide-5
SLIDE 5

Graph

Graph A graph G = (V, E) is a set V of vertices connected by an edge set E.

5 / 22

slide-6
SLIDE 6

Variations

Multi-Graph: Multiple edges between two vertices. Directed: Edges have a direction. Weighted: Vertices and/or edges have weights. Simple: No multiple edges, no loops. Simple Undirected Graph A simple undirected graph G = (V, E) is a set V of vertices con- nected by an edge set E ⊆ {{u, v} | u, v ∈ V, u = v}. An edge {u, v} is also writen as uv.

6 / 22

slide-7
SLIDE 7

Adjacency

Adjacency Two vertices u and v are adjacent if there is an edge connecting

  • them. This is sometimes writen as u ∼ v.

v b a c

v is adjacent with b and c but not with a.

7 / 22

slide-8
SLIDE 8

Neighbourhood

Neighbourhood The open neighbourhood N(v) = {u ∈ V | u = v, u ∼ v} of a vertex v is the set of vertices adjacent to v (not including v). The closed neighbourhood N[v] = N(v) ∪ {v} includes v.

v b a c

N(v) = {b, c} N[v] = {v, b, c}

8 / 22

slide-9
SLIDE 9

Degree

Degree The degree deg(v) of a vertex v is the number of incident edges. Note that the degree is not necessarily equal to the cardinality of neighbours.

v b a c

deg(v) = 3 deg(a) = 1 deg(b) = 5 deg(c) = 1

9 / 22

slide-10
SLIDE 10

Degree (directed)

Indegree, Outdegree For a vertex v, the indegree deg−(v) is the number of incoming edges, and the outdegree deg+(v) the number of incoming edges.

v b a c

deg+(v) = 2 deg+(a) = 0 deg+(b) = 3 deg+(c) = 1 deg−(v) = 1 deg−(a) = 1 deg−(b) = 2 deg−(c) = 0

10 / 22

slide-11
SLIDE 11

Degree

Let G = (V, E) be a graph. Then Lemma

  • v∈V

deg(v) = 2|E| If G is directed Lemma

  • v∈V

deg+(v) =

  • v∈V

deg−(v) = |E| It follows that the number of odd degree vertices is even.

11 / 22

slide-12
SLIDE 12

Path

Path In a graph a path p of length l is sequence of l +1 adjacent vertices,

  • i. e. p = (v0, . . . , vl) with vivi+1 ∈ E. A path is simple if all vertices

are different, i. e. vi = vj ⇔ i = j.

v b a c u

path (b, a, v, c, u)

v b a c u

simple path (a, v, b, u)

12 / 22

slide-13
SLIDE 13

Cycle

Cycle A cycle is a path that begins and ends with same vertex. A cycle is simple, if it doesn’t cross itself.

v b a c u

cycle (a, v, b, c, u, b, a)

v b a c u

simple cycle (a, v, c, u, b, a)

13 / 22

slide-14
SLIDE 14

Eulerian Cycles

slide-15
SLIDE 15

Recall: Seven Bridges of K¨

  • nigsberg

  • nigsberg (now Kaliningrad, Russia) around 1735

Problem: Find a walk through the city that would cross each bridge

  • nce and only once.

15 / 22

slide-16
SLIDE 16

Euler’s Solution

Represent problem as graph: Original problem: Find a walk through the city that would cross each bridge once and only once. Graph problem: Does G contain a path using each edge exactly

  • nce?

16 / 22

slide-17
SLIDE 17

Euler’s Solution

Given a graph G = (V, E) with |E| = m and index arithmetic modulo m. Eulerian Cycle An Eulerian cycle in a graph G is a sequence of vertices and edges v1, e1, . . . , vm, em, v1 such that ei = vivi+1 and ei = ej ⇔ i = j. Eulerian Path An Eulerian path in a graph G is a sequence of vertices and edges v1, e1, . . . , vm, em, vm+1 such that ei = vivi+1 and ei = ej ⇔ i = j. In an Eulerian cycle the start and end vertex hast to be equal. In an Eulerian path they can be different.

17 / 22

slide-18
SLIDE 18

Euler’s Solution

Theorem A connected graph has an Eulerian cycle if and only if the degree

  • f all vertices is even, i. e. ∀v ∈ V ∃k ∈ N: deg(v) = 2k.

Theorem A graph has an Eulerian path if and only if it is connected and has at most two vertices with an odd degree.

18 / 22

slide-19
SLIDE 19

Seven bridges of K¨

  • nigsberg

Degree of all vertices is odd.

5 3 3 3

Thus, there is no walk through the city that would cross each bridge

  • nce and only once.

19 / 22

slide-20
SLIDE 20

Algorithm

slide-21
SLIDE 21

Algorithm

Given a graph G. Does G have an Eulerian path? Algorithm based on Hierholzer’s algorithm from 1837.

a b c d e f

21 / 22

slide-22
SLIDE 22

Algorithm

  • 1. Determine the degree of all vertices.

3 4 5 3 3 4

21 / 22

slide-23
SLIDE 23

Algorithm

  • 2. If There are more than two vertices with an odd degree Then

Stop, G has no Eulerian path.

3 4 5 3 3 4

21 / 22

slide-24
SLIDE 24

Algorithm

  • 3. Choose any starting vertex v. Select a vertex with odd degree if

possible.

3 4 4 2 3 4

21 / 22

slide-25
SLIDE 25

Algorithm

  • 4. Follow a trail T of edges from v until geting stuck.

a b c d e f

T = a, e, f , d, b, c, e

21 / 22

slide-26
SLIDE 26

Algorithm

  • 5. While There is a vertex v belonging to the current trail T but

has adjacent edges not part of T.

a b c d e f

T = a, e, f , d, b, c, e

21 / 22

slide-27
SLIDE 27

Algorithm

5.1 Start another trail T ′ from v, following unused edges until returning to v.

a b c d e f

T = a, e, f , d, b, c, e T ′ = b, f , c, a, b

21 / 22

slide-28
SLIDE 28

Algorithm

5.1 Start another trail T ′ from v, following unused edges until returning to v.

a b c d e f

T = a, e, f , d, b, c, e T ′ = b, f , c, a, b

21 / 22

slide-29
SLIDE 29

Algorithm

5.2 Join the tour T ′ formed in this way to the previous trail T.

a b c d e f

T = a, e, f , d, b, f , c, a, b, c, e

21 / 22

slide-30
SLIDE 30

Complete Algorithm

Given a graph G = (V, E).

  • 1. Determine the degree of all vertices.
  • 2. If There are more than two vertices with an odd degree Then

Stop, G has no Eulerian path.

  • 3. Choose any starting vertex v. Select a vertex with odd degree if

possible.

  • 4. Follow a trail T of edges from v until geting stuck.
  • 5. While There is a vertex v belonging to the current trail T but

has adjacent edges not part of t.

5.1 Start another trail T ′ from v, following unused edges until returning to v. 5.2 Join the tour T ′ formed in this way to the previous trail T.

This algorithm can be implemented in O(|E|) time.

22 / 22