Download presentation
Presentation is loading. Please wait.
Published byChester Tyler Modified over 8 years ago
1
1 Euler and Hamilton paths Jorge A. Cobb The University of Texas at Dallas
2
2 Paths and the adjacency matrix The powers of the adjacency matrix A r (with normal, not boolean multiplication) contain the number of paths from v i to v j with exactly r edges Proof: By induction. True for A 1 = A. When we consider A r+1, the (i, j)-th entry there will be b i1 a 1j + b i2 a 2j +... + b in a nj where b ik are the entries in A r and a kj are the entries in A. So that entry will add the count of paths from all possible paths with r edges that can be extended to end at v j.
3
3 The bridges of Königsberg The town of Königsberg (East Prussia; now Kaliningrad, Russia) is divided in four sections with seven bridges Is it possible to start somewhere and return to that point crossing all bridges exactly once?
4
4 A graph for Königsberg We represent the four regions as vertices and the bridges as edges (rearranging because of isomorphism)
5
5 Euler circuits and paths An Euler circuit in a graph is a simple circuit containing every edge of the graph. An Euler path in a graph is a simple path containing every edge of the graph. Theorem 1: A finite graph has an Euler circuit if and only if it is connected and all vertices have even degree.
6
6 Proof: “Only if” direction Suppose that a graph has an Euler circuit. Then the graph must be connected. The Euler circuit starts at a vertex v. Every time any vertex other the last vertex in the circuit is entered (including v if it is visited multiple times), the circuit must leave this vertex. Thus, the edges entering and leaving each vertex are paired, adding 2 to that vertex’s degree each time it is visited. 2 is also added to v’s degree for the first and last edge, so all vertex degrees are even.
7
7 Proof: “If” direction Suppose that all vertices have even degrees. We construct an Euler circuit as follows: Start at an arbitrary vertex, and construct a path randomly, until we can’t do so anymore (this will happen at some point because the graph is finite). This process must terminate at v, because each time the path passes from a vertex u it subtracts 2 from the remaining edges incident to u, and those are an even number. Therefore, we can always leave any vertex other than v.
8
8 Proof: “If” direction We have therefore constructed a simple circuit. Does this use all edges? If not, consider the subgraphs obtained by deleting the circuit we just constructed. Because the original graph is connected, these subgraphs will have at least a vertex in common with our path. Follow the above process in each such subgraph, and splice the circuits together to obtain an Euler circuit for the original graph.
9
9 Assume you started at a You get stuck once you go back to a.
10
10 Euler paths Theorem 2: A finite graph has an Euler path (but not an Euler circuit) if and only if it is connected and exactly two vertices have odd degrees. Proof: Analogous to Theorem 1. The two vertices with the odd degrees must be the first and last vertices in the Euler path (see the book for details)
11
11 The bridges of Königsberg Is there an Euler circuit or path? NO because all four vertices have odd degree Modern Königsberg Two brigdes were destroyed by British bombers in WW II. Two bridges were replaced by a highway by the Russians. Three bridges plus the highway remain The graph has now two vertices with degree 2 and two with degree 3, so it has an Euler path
12
12 Extensions of the problem Identified regions The blue prince wants to be able to visit all bridges starting at his castle and ending at the inn. Which new bridge should he build?
13
13 Solution We need an Euler path from the blue castle to the inn. We have the following degrees: blue castle, red castle, and church: 3 inn: 5 We need to make the degrees of the red castle and church even – build a bridge between them
14
14 More extensions The red prince, furious with the previous development, wants to build a ninth bridge so that he can go from his castle to the inn and the blue prince can no longer do so. The bishop, upset with all this bridge building and the excessive drinking, wants to build a tenth bridge so that everybody can go home (i.e., there is an Euler circuit).
15
15 Hamilton circuits and paths A Hamilton circuit (path) is a simple circuit (path) that contains all vertices and passes through each vertex of the graph exactly once. How can we tell if a graph has a Hamilton circuit or path? Not easily, i.e., in general, in not less than exponential time in the number of vertices There are some tests that can exclude graphs (e.g., no vertex of degree one for circuits).
16
16 Ham. Circuits and Paths
17
17 Number of Hamilton paths Consider the complete graph K n with n > 2. How many Hamilton circuits are there? Select any vertex as the start vertex (because all vertices will belong to the circuit the choice doesn’t matter). From this vertex we can choose n-1 successor vertices, from each of them n-2 vertices, and so on, for a total of (n-1)! circuits. Because direction doesn’t matter, the distinct circuits are (n- 1)!/2.
18
18 Weighted graphs A weighted graph is a graph where numbers (weights or costs) have been attached to each edge. Example: In a graph for flight connections, weights could represent time needed for each flight, distance traveled, or cost of traveling on that flight. In a computer network, costs could represent the delay for a message to travel through a link.
19
19 Path length In a graph without weights, we define the length of a path as the number of edges in it. In a weighted graph, the path length is a function of the weights of the edges in the path, usually the sum of those weights.
20
20 The Traveling Salesman problem A traveling salesman needs to visit n cities, going to each city exactly once, and return to his starting city. Assume every city is connected to every other city, but the cost of traveling differs for each city pair. What is the sequence of cities that minimizes the overall cost? Equivalent formulation: Find the Hamilton circuit in K n with shortest length.
21
21 Solving the TSP No algorithm is known that will guarantee finding the best solution except by examining all possible circuits (or equivalent approaches). For n = 25, (n – 1)! / 2 = 24! / 2 ≈ 3 × 10 23. If we take one nanosecond to calculate the cost of each circuit, we still need 3 × 10 14 seconds, or about 10 million years. The problem is provably NP-complete.
22
22 TSP Problems Planning routes 980 cities in Luxembourg 24,978 cities in Sweden (solved May 2004) 1,904,711 cities in the world Drilling printed circuit boards cost of moving the drill and possibly changing drills because of different hole sizes Genome sequencing edges represent likelihood that a fragment of DNA follows another fragment
23
23 Example tour on circuit board 3,038 points to visit
24
24 Exact methods for TSP We can find exact solutions with techniques that remember previous partial results and re- use them rather than redoing the work. Techniques from linear programming are applicable here. For example, the optimal tour of 33,810 points on a circuit board was found in 2005 using multiple computers and a total of only 15.7 CPU-years.
25
25 Approximate solutions Reasonably fast algorithms that guarantee an error bound, i.e., a solution with cost at most c times of the original cost We can achieve c = 1.5 if the costs obey the triangle inequality, i.e., guarantee an error bound with certain probability, typically 97%-98% Based on random walks and Markov chains do not guarantee anything, but are likely to produce a reasonable solution Greedy algorithms d(A, C) ≤ d(A, B) + d(B, C)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.