Eulerian and Hamiltonian Paths
Total Page:16
File Type:pdf, Size:1020Kb
Eulerian and Hamiltonian Paths 1. Euler paths and circuits 1.1. The Könisberg Bridge Problem Könisberg was a town in Prussia, divided in four land regions by the river Pregel. The regions were connected with seven bridges as shown in figure 1(a). The problem is to find a tour through the town that crosses each bridge exactly once. Leonhard Euler gave a formal solution for the problem and –as it is believed- established the graph theory field in mathematics. (a) (b) Figure 1: The bridges of Könisberg (a) and corresponding graph (b) 1.2. Defining Euler paths Obviously, the problem is equivalent with that of finding a path in the graph of figure 1(b) such that it crosses each edge exactly one time. Instead of an exhaustive search of every path, Euler found out a very simple criterion for checking the existence of such paths in a graph. As a result, paths with this property took his name. Definition 1: An Euler path is a path that crosses each edge of the graph exactly once. If the path is closed, we have an Euler circuit. In order to proceed to Euler’s theorem for checking the existence of Euler paths, we define the notion of a vertex’s degree. Definition 2: The degree of a vertex u in a graph equals to the number of edges attached to vertex u. A loop contributes 2 to its vertex’s degree. 1.3. Checking the existence of an Euler path The existence of an Euler path in a graph is directly related to the degrees of the graph’s vertices. Euler formulated the three following theorems of which the first two set a sufficient and necessary condition for the existence of an Euler circuit or path in a graph respectively. Theorem 1: An undirected graph has at least one Euler path iff it is connected and has two or zero vertices of odd degree. Theorem 2: An undirected graph has an Euler circuit iff it is connected and has zero vertices of odd degree. Theorem 3: The sum of the degrees of every vertex of a graph is even and equals to twice the number of edges. A proof for Theorems 1.1 and 1.2(as a special case of 1.1) follows. Proof: ÞAn Euler trail exists. As the path is traversed, each time that a vertex is reached we cross two edges attached to the vertex and have not been crossed yet. Thus, all vertices, except maybe the starting vertex a and the ending vertex b, have even degrees. If a ºb we have an Euler circuit and if a ¹ b we have an open path. ÜInduction on the number of vertices Induction beginning: |V| = 2. Elementary case Induction assumption: For |V| £ n the theorem holds. Induction step: |V| = n + 1. If we have two vertices with odd degrees a and b we can find a longest path beginning at a and ending at b. For any left edges, we can use the condition assumed by the induction. If we have no vertices of odd degree we use the same method except a is the begging and ending vertex. Example: Figure 2 shows some graphs indicating the distinct cases examined by the preceding theorems. Graph (a) has an Euler circuit, graph (b) has an Euler path but not an Euler circuit and graph (c) has neither a circuit nor a path. (a) (b) (c) Figure 2: A graph containing an Euler circuit (a), one containing an Euler path (b) and a non- Eulerian graph (c) 1.4. Finding an Euler path There are several ways to find an Euler path in a given graph. Since it is a relatively simple problem it can solve intuitively respecting a few guidelines: · Always leave one edge available to get back to the starting vertex (for circuits) or to the other odd vertex (for paths) as the last step. · Don't use an edge to go to a vertex unless there is another edge available to leave that vertex (except for the last step). This technique certainly gives results for simple graphs but we surely need a formal algorithm to find Euler circuits. In the following sections we present two algorithms serving that purpose. Fluery’s algorithm Fluery’s algorithm can be applied in searches for both Euler circuits and paths. FLUERY Input: A connected graph G = (V, E) with no vertices of odd degree Output: A sequence P of vertices and their connecting edges indicating the Euler circuit. 1 Choose any vertex u0 in G. 2 P = u0 3 if Pi = u0e1u1e2…eiui choose edge ei+1 so that 1. ei+1 is adjacent to ei 2. Removal of ei+1 does not disconnect G – {e1,…, ei} (i.e. ei+1 is not a bridge). 4 if P includes all edges in E return P 5 goto 3 The algorithm for finding an Euler path instead of a circuit is almost identical to the one just described. Their only difference lies in step 1 where we must choose one of the vertices of odd degree as the beginning vertex. Example: Figure 3 demonstrates some important steps in the process described by the algorithm 1.4. The numbers that label each edge indicate their index in the Euler circuit. 1 2 3 (a) (b) 1 5 4 2 13 6 3 7 10 9 12 8 11 (c) Figure 3: The input graph (a). The bold line is a bridge but we have no other choice (b). The output graph, showing the sequence of edges in the Euler circuit (c). A constructive algorithm The ideas used in the proof of Euler’s theorem can lead us to a recursive constructive algorithm to find an Euler path in an Eulerian graph. CONSTRUCT Input: A connected graph G = (V, E) with two vertices of odd degree. Output: The graph with its edges labeled according to their order of appearance in the path found. 1 Find a simple cycle in G. 2 Delete the edges belonging in C. 3 Apply algorithm to the remaining graph. 4 Amalgamate Euler cycles found to obtain the complete Euler cycle. The process described can be extended to handle Euler paths as well. We are obliged to start from a vertex of odd degree u. Then we add a “phantom edge” between the vertices of odd degree and thus ensure that every vertex has an even degree. We find the circuit starting and ending at u and then remove the phantom edge to obtain the Euler path. Example: Figure 4 demonstrates the constructive algorithm’s steps in a graph. 4(a) shows the initial graph, and 4(b), 4(c) show the simple cycle found. 4(d) shows the next cycle and 4(e) the amalgamation of the two cycles found. The process continues and we result to the graph of figure 4(i). (a) (b) 2 1 2 1 3 3 (c) (d) 9 9 8 8 10 10 1 7 1 7 2 6 2 11 6 11 3 5 3 5 4 (e) (f) 9 9 8 8 10 14 10 14 1 13 7 1 13 7 2 12 2 12 15 11 6 15 11 6 3 5 3 5 4 4 (g) 9 (h) 8 10 11 13 7 12 17 16 1 6 2 18 14 15 3 5 4 (i) Figure 4: Applying the algorithm to graph 4(a) and resulting to graph 4(i) 1.5 Expanding to directed graphs The results aforementioned can easily be adapted to directed graphs. We proceed to two definitions analogous to definition 1.1. Definition 3: The in-degree of a vertex in a directed graph is the number of edges incoming to that vertex. Definition 4: The out-degree of a vertex in a directed graph is the number of edges outgoing from that vertex. The condition that a directed graph must satisfy to have an Euler circuit is defined by the following theorem. Theorem 4: A directed graph G has an Euler circuit iff it is connected and for every vertex u in G in-degree(u) = out-degree(u). Example: An interesting problem (and with some practical worth as well) is the following: Place 2n binary digits in a circular table in such a way that the 2n sequences of n digits are all different. The solution is produced by constructing a graph with 2n-1 vertices each of them n-1 labeled with one of the 2 numbers with n-1 digits. The vertex labeled with a1a2a3...an-1 has an outgoing edge to the vertex a2a3a4....an-10. The edge is labeled with a1a2a3...an-10. There is also an edge from a1a2a3...an-1 to a2a3a4....an-11 labeled with a1a2a3...an-11. The resulting graph has an Euler circuit corresponding to a circular ordering of the possible bit sequences. Figure 5 shows the results for n = 4. 0000 000 0001 10000 1001 001 100 0010 0100 010 0101 1010 1100 0011 1011 101 1101 011 110 0110 0111 111 1110 1111 Figure 5: Euler Path {e0e1e2e5e10e4e9e3e6e13e11e7e15e14e12e8} corresponds to the desired order of the bit sequences. 1.6 Applications Eulerian graphs are used rather extensively, as they’re necessary to solve important problems in telecommunication, parallel programming development and coding. Moreover, the corresponding theory underlies in many classic mathematical problems. In the next sections, we examine some interesting examples Line Drawings You can consider a line drawing as a graph whose vertices are not shown and are placed in the intersection of each pair of adjacent edges.