Download presentation

Presentation is loading. Please wait.

Published byAaron Kicker Modified over 6 years ago

1
Lecture 21 Paths and Circuits CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

2
CSCI 1900 Lecture 21 - 2 Lecture Introduction Reading –Rosen Section 10.1 Application of Graph Theory –Euler Paths and Circuits –Hamiltonian Paths and Circuits –Traveling Salesman Problem

3
CSCI 1900 Lecture 21 - 3 Definitions Given a graph G and vertices v and w in G –A walk is a finite alternating sequence of vertices and edges of G –A path from v to w is a walk that does not contain repeated edges –A simple path from v to w is path that does not contain a repeated vertex –A closed walk is a walk that starts and ends at the same vertex –A circuit is a closed walk that does not contain a repeated edge –A simple circuit is a circuit that has no repeated vertices except the first and the last

4
CSCI 1900 Lecture 21 - 4 Example: Walks, Paths, Circuits A walk –v 2 e 2 v 3 e 6 v 5 e 5 v 2 e 2 v 3 e 3 v 4 A path –v 2 e 2 v 3 e 6 v 5 e 5 v 2 e 1 v 1 A simple path –v 3 e 6 v 5 e 5 v 2 e 1 v 1 A circuit –v 2 e 5 v 5 e 6 v 3 e 3 v 4 e 4 v 1 e 7 v 3 e 2 v 2 A simple circuit –v 2 e 5 v 5 e 6 v 3 e 7 v 1 e 1 v 2 v2v2 v1v1 v3v3 v4v4 v5v5 e6e6 e5e5 e4e4 e3e3 e2e2 e1e1 Consider the graph e7e7

5
CSCI 1900 Lecture 21 - 5 Euler Circuits Given a graph G, an Euler circuit for G is a sequence of adjacent vertices and edges in G that –Starts and ends at the same vertex, –Uses every vertex of G at least once, and –Uses every edge of G exactly once

6
CSCI 1900 Lecture 21 - 6 Theorems on Euler Circuits The following theorem is quoted without proof: –If a graph has an Euler Circuit, then every vertex is of even degree The Contrapositive –If some vertex of a graph is of odd degree, then the graph does not have a Euler Circuit

7
CSCI 1900 Lecture 21 - 7 Example: Euler Circuit Does the graph have an Euler Circuit? Why or why not? If not, how many edges must be added or removed to admit the existence of an Euler Circuit? v2v2 v1v1 v3v3 v4v4 v5v5 e6e6 e5e5 e4e4 e3e3 e2e2 e1e1 Consider the prior graph e7e7

8
CSCI 1900 Lecture 21 - 8 Bridges of Königsberg Problem The town of Königsberg was built at the confluence of two branches of the Pregel river. The Pregel river divides the land into four land masses. These land masses are connected by seven bridges. The citizens spent many a pleasant Sunday afternoon trying to find a walk that would start on one of the land masses, cross all the bridges exactly once and end on the starting land mass.

9
CSCI 1900 Lecture 21 - 9 Map of Königsberg Source: http://commons.wikimedia.org/wiki/File:Konigsberg_bridges.png

10
CSCI 1900 Lecture 21 - 10 The Solution In 1736, Leonhard Euler resolved the problem with reasoning equivalent to the two previously quoted theorem Draw the graph corresponding to the map of Konigsberg Determine the degree of the vertices of your graph By applying the theorem, show that no circuit is possible

11
CSCI 1900 Lecture 21 - 11 Hamiltonian Circuits A related circuit is the Hamiltonian circuit Given a graph G, a Hamiltonian circuit, H of G, is a sequence of adjacent vertices and distinct edges, in which every vertex of G appears exactly once in H

12
CSCI 1900 Lecture 21 - 12 If a graph G has a Hamiltonian circuit, then G has a subgraph H with the following properties –H contains every vertex in G –H is connected –H has the same number of edges as vertices –Every vertex of H has degree 2 Theorem on Hamilton Circuits

13
Traveling Salesman Problem Given a set of cities (represented by vertices) that are connected by a set of roads (represented by edges) Suppose that a salesman must travel to each of the cities exactly once, starting and ending at one of the cities –What route, driven over exiting roads, minimizes the distance that the salesman must drive? CSCI 1900 Lecture 21 - 13

14
CSCI 1900 Lecture 21 - 14 Example: Traveling Salesman Given the above weighted graph, what is the minimum distance the salesman must travel, starting and ending in city A? D C BA 30 25 40 50 35

15
CSCI 1900 Lecture 21 - 15 Solution: Traveling Salesman List all Hamiltonian Circuits Calculate the total distance for each circuit Select the minimum circuit CircuitDistance Traveled ABCDA30 + 25 + 40 + 30 = 125 ACDBA35 + 40 + 50 + 30 = 155 ADBCA30 + 50 + 25 + 35 = 140 ABDCA30 + 50 + 40 + 35 = 155 (ACDBA backwards) ACBDA30 + 50 + 25 + 35 = 140 (ADBCA backwards) ADCBA30 + 40 + 25 + 30 = 125 (ABCDA backwards)

16
CSCI 1900 Lecture 21 - 16 Traveling Salesman Problem Exact solution? –Only known general solution is by enumeration of all possible routes –For a complete graph with n nodes Since we must start and end with one of the nodes, we need the number of permutations of (n-1) vertices, taken (n-1) at a time n-1 P n-1 = (n-1)! Hamiltonian circuits For n = 10 number of circuits =362,880 For n = 50 number of circuits > 1 x 10 64

17
CSCI 1900 Lecture 21 - 17 Traveling Salesman (cont) There exist approximate solutions that yield a “good” solution, but not the best solution –“Good” means that the approximate solution will have a smaller total distance than most of the Hamiltonian circuits

18
CSCI 1900 Lecture 21 - 18 Key Concepts Summary Walks, paths, and circuits Euler Circuits –Application: Seven Bridges of Königsberg Hamiltonian Circuits –Application: Traveling Salesman problem Reading for next time –No further readings

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google