introduction to graphs historical motivation seven
play

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


  1. Introduction to Graphs

  2. Historical Motivation

  3. 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

  4. Definitions

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

  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

  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 a c b v is adjacent with b and c but not with a . 7 / 22

  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 a c b N ( v ) = { b , c } N [ v ] = { v , b , c } 8 / 22

  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 a c b deg ( v ) = 3 deg ( a ) = 1 deg ( b ) = 5 deg ( c ) = 1 9 / 22

  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 a c b 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

  11. Degree Let G = ( V , E ) be a graph. Then Lemma � deg ( v ) = 2 | E | v ∈ V If G is directed Lemma � � deg + ( v ) = deg − ( v ) = | E | v ∈ V v ∈ V It follows that the number of odd degree vertices is even. 11 / 22

  12. Path Path In a graph a path p of length l is sequence of l + 1 adjacent vertices, i. e. p = ( v 0 , . . . , v l ) with v i v i + 1 ∈ E . A path is simple if all vertices are different, i. e. v i � = v j ⇔ i � = j . v v a a c c b b u u path simple path ( b , a , v , c , u ) ( a , v , b , u ) 12 / 22

  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 v a a c c b b u u cycle simple cycle ( a , v , b , c , u , b , a ) ( a , v , c , u , b , a ) 13 / 22

  14. Eulerian Cycles

  15. Recall: 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. 15 / 22

  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 once? 16 / 22

  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 v 1 , e 1 , . . . , v m , e m , v 1 such that e i = v i v i + 1 and e i � = e j ⇔ i � = j . Eulerian Path An Eulerian path in a graph G is a sequence of vertices and edges v 1 , e 1 , . . . , v m , e m , v m + 1 such that e i = v i v i + 1 and e i � = e j ⇔ 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

  18. Euler’s Solution Theorem A connected graph has an Eulerian cycle if and only if the degree of all vertices is even, i. e. ∀ v ∈ V ∃ k ∈ N : deg ( v ) = 2 k . 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

  19. Seven bridges of K¨ onigsberg Degree of all vertices is odd. 3 5 3 3 Thus, there is no walk through the city that would cross each bridge once and only once. 19 / 22

  20. Algorithm

  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

  22. Algorithm 1. Determine the degree of all vertices. 3 4 5 3 3 4 21 / 22

  23. Algorithm 2. If There are more than two vertices with an odd degree T hen Stop , G has no Eulerian path. 3 4 5 3 3 4 21 / 22

  24. Algorithm 3. Choose any starting vertex v . Select a vertex with odd degree if possible. 3 4 4 2 3 4 21 / 22

  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

  26. Algorithm 5. W hile 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

  27. Algorithm 5.1 Start another trail T ′ from v , following unused edges until returning to v . a b c d e f T ′ = b , f , c , a , b T = a , e , f , d , b , c , e 21 / 22

  28. Algorithm 5.1 Start another trail T ′ from v , following unused edges until returning to v . a b c d e f T ′ = b , f , c , a , b T = a , e , f , d , b , c , e 21 / 22

  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

  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 T hen 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend