Fundamentals of Informatics Introduction to Algorithms and...

27
Fundamentals of Informatics Introduction to Algorithms and Informatics Lecture 2: Graphs as models I Prof: David Avis I Research bldg. No. 7, room 404 I www.i-kyoto-u.ca.jp/avis I Check course web page at least once a week ! I TA: Yang Cao

Transcript of Fundamentals of Informatics Introduction to Algorithms and...

Page 1: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Fundamentals of InformaticsIntroduction to Algorithms and Informatics

Lecture 2: Graphs as models

I Prof: David Avis

I Research bldg. No. 7, room404

I www.i-kyoto-u.ca.jp/∼avis

I Check course web page at leastonce a week !

I TA: Yang Cao

Page 2: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 3: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 4: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 5: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 6: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 7: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 8: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

How to pass this course smiling!

I Attend the lectures !

I Do all the reading assignments on the lecturesummaries web page

I Do the exercises after each lecture

I 3 reports consisting of exercises from 3-4 lectures

I Report due dates: Wed May 14, Wed June 29, WedJuly 16 in class (or give to Yang Cao)

I Ask questions !

www.i-kyoto-u.ca.jp/∼avis

Page 9: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Kyoto bridge problem

I Is it possible to cross each bridge exactly once?

I If so, can you do so and start and end at the same place?

Page 10: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Kyoto bridge problem

I Is it possible to cross each bridge exactly once?

I If so, can you do so and start and end at the same place?

Page 11: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Kyoto bridge problem

I Is it possible to cross each bridge exactly once?

I If so, can you do so and start and end at the same place?

Page 12: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Konigsberg bridges: 1735 and now

I The problem is to cross each bridge exactly once and end at thestarting point

I This is the Euler circuit problem ...

I ... and can be solved in linear time

I Considered as the birth of graph theory

Page 13: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Konigsberg bridges: 1735 and now

I The problem is to cross each bridge exactly once and end at thestarting point

I This is the Euler circuit problem ...

I ... and can be solved in linear time

I Considered as the birth of graph theory

Page 14: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Konigsberg bridges: 1735 and now

I The problem is to cross each bridge exactly once and end at thestarting point

I This is the Euler circuit problem ...

I ... and can be solved in linear time

I Considered as the birth of graph theory

Page 15: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Konigsberg bridges: 1735 and now

I The problem is to cross each bridge exactly once and end at thestarting point

I This is the Euler circuit problem ...

I ... and can be solved in linear time

I Considered as the birth of graph theory

Page 16: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Konigsberg bridges: 1735 and now

I The problem is to cross each bridge exactly once and end at thestarting point

I This is the Euler circuit problem ...

I ... and can be solved in linear time

I Considered as the birth of graph theory

Page 17: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Euler Circuits: Konigsberg bridge problem (1735)

B

g

e

f

C

c

a b

d

A D

I A graph consists of a set of vertices V and edges E connectingvertices

I Vertices in graph correspond to land, edges to bridges

I Euler’s Theorem: A circuit exists that crosses every bridge if andonly if each vertex in the corresponding graph has even degree

I We can find the circuit in linear time

Page 18: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Euler Circuits: Konigsberg bridge problem (1735)

B

g

e

f

C

c

a b

d

A D

I A graph consists of a set of vertices V and edges E connectingvertices

I Vertices in graph correspond to land, edges to bridges

I Euler’s Theorem: A circuit exists that crosses every bridge if andonly if each vertex in the corresponding graph has even degree

I We can find the circuit in linear time

Page 19: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Euler Circuits: Konigsberg bridge problem (1735)

B

g

e

f

C

c

a b

d

A D

I A graph consists of a set of vertices V and edges E connectingvertices

I Vertices in graph correspond to land, edges to bridges

I Euler’s Theorem: A circuit exists that crosses every bridge if andonly if each vertex in the corresponding graph has even degree

I We can find the circuit in linear time

Page 20: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Euler Circuits: Konigsberg bridge problem (1735)

B

g

e

f

C

c

a b

d

A D

I A graph consists of a set of vertices V and edges E connectingvertices

I Vertices in graph correspond to land, edges to bridges

I Euler’s Theorem: A circuit exists that crosses every bridge if andonly if each vertex in the corresponding graph has even degree

I We can find the circuit in linear time

Page 21: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Extensions: Chinese Postman Problem

I If the graph has exactly two vertices of odd degree we can find apath visiting each edge exactly once

I What if there are more than two vertices of odd degree?

I Find a minimum length path that visits each edge at least once.

I Proposed by Kwan Mei-Ko (1962) solved by Jack Edmonds and EllisJohnson (1973)

I Many applications of this: postal delivery, street cleaning, garbagepickup, snow removal, ...

Page 22: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Extensions: Chinese Postman Problem

I If the graph has exactly two vertices of odd degree we can find apath visiting each edge exactly once

I What if there are more than two vertices of odd degree?

I Find a minimum length path that visits each edge at least once.

I Proposed by Kwan Mei-Ko (1962) solved by Jack Edmonds and EllisJohnson (1973)

I Many applications of this: postal delivery, street cleaning, garbagepickup, snow removal, ...

Page 23: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Extensions: Chinese Postman Problem

I If the graph has exactly two vertices of odd degree we can find apath visiting each edge exactly once

I What if there are more than two vertices of odd degree?

I Find a minimum length path that visits each edge at least once.

I Proposed by Kwan Mei-Ko (1962) solved by Jack Edmonds and EllisJohnson (1973)

I Many applications of this: postal delivery, street cleaning, garbagepickup, snow removal, ...

Page 24: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Extensions: Chinese Postman Problem

I If the graph has exactly two vertices of odd degree we can find apath visiting each edge exactly once

I What if there are more than two vertices of odd degree?

I Find a minimum length path that visits each edge at least once.

I Proposed by Kwan Mei-Ko (1962) solved by Jack Edmonds and EllisJohnson (1973)

I Many applications of this: postal delivery, street cleaning, garbagepickup, snow removal, ...

Page 25: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Extensions: Chinese Postman Problem

I If the graph has exactly two vertices of odd degree we can find apath visiting each edge exactly once

I What if there are more than two vertices of odd degree?

I Find a minimum length path that visits each edge at least once.

I Proposed by Kwan Mei-Ko (1962) solved by Jack Edmonds and EllisJohnson (1973)

I Many applications of this: postal delivery, street cleaning, garbagepickup, snow removal, ...

Page 26: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

ExercisesI Let G = (V ,E ) be a connected undirected graph with exactly two

vertices, A and B, of odd degree. Prove that any maximal lengthpath with no repeated edges that starts at A must end at B.Conclude that after this path has been removed from G all vertexdegrees must be even.

I Consider the Montreal map at the top of the next slide. Decidewhether or not there is a path (or circuit) that crosses each bridge.If so, give the path (or circuit). (Consider all lines crossing the wateras bridges)

I Consider the new bridge connecting highway 25 shown in yellowbelow. How does this change the answer to the preceding question?

Page 27: Fundamentals of Informatics Introduction to Algorithms and ...cgm.cs.mcgill.ca/~avis/Kyoto/courses/ia/2014/notes/slide2.pdf · Extensions: Chinese Postman Problem I If the graph has

Montreal bridge problem

Montreal map before 2011