Circuits (Eulerian and Hamiltonian) Ioan Despi - - PowerPoint PPT Presentation

circuits
SMART_READER_LITE
LIVE PREVIEW

Circuits (Eulerian and Hamiltonian) Ioan Despi - - PowerPoint PPT Presentation

Circuits (Eulerian and Hamiltonian) Ioan Despi despi@turing.une.edu.au University of New England July 25, 2013 Outline 1 Recall 2 Bridges of K onigsberg 3 The Traveling Salesperson Problem 4 Eulerian 5 Eulers Theorem 6 Hamiltonian 7


slide-1
SLIDE 1

Circuits

(Eulerian and Hamiltonian) Ioan Despi

despi@turing.une.edu.au

University of New England

July 25, 2013

slide-2
SLIDE 2

Outline

1 Recall 2 Bridges of K¨

  • nigsberg

3 The Traveling Salesperson Problem 4 Eulerian 5 Euler’s Theorem 6 Hamiltonian 7 Fleury’s Algorithm

Ioan Despi – Discrete Mathematics 2 of 31

slide-3
SLIDE 3

Recall

A graph is a relational structure made up of vertices and edges.

Ioan Despi – Discrete Mathematics 3 of 31

slide-4
SLIDE 4

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices. Ioan Despi – Discrete Mathematics 3 of 31

slide-5
SLIDE 5

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop.

Ioan Despi – Discrete Mathematics 3 of 31

slide-6
SLIDE 6

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

Ioan Despi – Discrete Mathematics 3 of 31

slide-7
SLIDE 7

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself! Ioan Despi – Discrete Mathematics 3 of 31

slide-8
SLIDE 8

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

Ioan Despi – Discrete Mathematics 3 of 31

slide-9
SLIDE 9

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

◮ A loop adds 2 to the degree of a vertex! Ioan Despi – Discrete Mathematics 3 of 31

slide-10
SLIDE 10

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

◮ A loop adds 2 to the degree of a vertex!

A vertex with degree 0 is an isolated vertex.

Ioan Despi – Discrete Mathematics 3 of 31

slide-11
SLIDE 11

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

◮ A loop adds 2 to the degree of a vertex!

A vertex with degree 0 is an isolated vertex. A path (walk) in a graph is a route among vertices along the graph’s edges such that no edge is used more than once.

Ioan Despi – Discrete Mathematics 3 of 31

slide-12
SLIDE 12

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

◮ A loop adds 2 to the degree of a vertex!

A vertex with degree 0 is an isolated vertex. A path (walk) in a graph is a route among vertices along the graph’s edges such that no edge is used more than once.

◮ Paths are specified by listing adjacent vertices from the beginning of the

path to the end of the path.

Ioan Despi – Discrete Mathematics 3 of 31

slide-13
SLIDE 13

Recall

A graph is a relational structure made up of vertices and edges.

◮ The edges of a graph express the relationships among the vertices.

An edge that connects a vertex to itself is a loop. Two vertices are adjacent if there is an edge joining them.

◮ If a vertex has a loop, the vertex is adjacent to itself!

The degree of a vertex is the total number of edges at that vertex.

◮ A loop adds 2 to the degree of a vertex!

A vertex with degree 0 is an isolated vertex. A path (walk) in a graph is a route among vertices along the graph’s edges such that no edge is used more than once.

◮ Paths are specified by listing adjacent vertices from the beginning of the

path to the end of the path.

A path that starts and ends at the same vertex is called a circuit.

Ioan Despi – Discrete Mathematics 3 of 31

slide-14
SLIDE 14

Recall (cont.)

A graph is connected if any two of its vertices can be joined by a path.

Ioan Despi – Discrete Mathematics 4 of 31

slide-15
SLIDE 15

Recall (cont.)

A graph is connected if any two of its vertices can be joined by a path. A graph that is not connected is disconnected.

Ioan Despi – Discrete Mathematics 4 of 31

slide-16
SLIDE 16

Recall (cont.)

A graph is connected if any two of its vertices can be joined by a path. A graph that is not connected is disconnected.

◮ The resulting pieces of a disconnected graph are called components of the

graph.

Ioan Despi – Discrete Mathematics 4 of 31

slide-17
SLIDE 17

Recall (cont.)

A graph is connected if any two of its vertices can be joined by a path. A graph that is not connected is disconnected.

◮ The resulting pieces of a disconnected graph are called components of the

graph.

If erasing an edge of a connected graph would cause the graph to be disconnected, that edge is called a bridge.

Ioan Despi – Discrete Mathematics 4 of 31

slide-18
SLIDE 18

Bridges of K¨

  • nigsberg

The city of K¨

  • ningsberg occupied both banks and two islands of a river. The

islands and the riverbanks were connected by seven bridges, as indicated in Figure 1.The question is if there is a walk around the city that crosses each bridge exactly once.

Figure 1 : The city of K¨

  • ningsberg

Ioan Despi – Discrete Mathematics 5 of 31

slide-19
SLIDE 19

Bridges of K¨

  • nigsberg (cont.)

Your tasks are:

1 Represent the problem as a graph. 2 Represent the problem using predicate calculus: devise a predicate and

use it to represent facts and rules in a Prolog-style manner. (Prolog is a programming language used in Artificial Intelligence)

3 Are the two representations equivalent? 4 Try to solve the problem (optional). Ioan Despi – Discrete Mathematics 6 of 31

slide-20
SLIDE 20

Trying to solve the problem. . .

(from http://mathforum.org/isaac/problems/bridges1.html) Figure 2 : First attempt

Ioan Despi – Discrete Mathematics 7 of 31

slide-21
SLIDE 21

Trying to solve the problem. . .

(from http://mathforum.org/isaac/problems/bridges1.html) Figure 2 : First attempt Figure 3 : Second attempt

Ioan Despi – Discrete Mathematics 7 of 31

slide-22
SLIDE 22

Trying to solve the problem. . .

What if we delete a bridge? Figure 4 : Third attempt

Ioan Despi – Discrete Mathematics 8 of 31

slide-23
SLIDE 23

Bridges of K¨

  • nigsberg (solution)

Euler invented graph theory to solve this problem.

Ioan Despi – Discrete Mathematics 9 of 31

slide-24
SLIDE 24

Bridges of K¨

  • nigsberg (solution)

Euler invented graph theory to solve this problem. We will use riverbanks (rb1 and rb2) and islands (i1 and i2) as nodes in the graph.

Ioan Despi – Discrete Mathematics 9 of 31

slide-25
SLIDE 25

Bridges of K¨

  • nigsberg (solution)

Euler invented graph theory to solve this problem. We will use riverbanks (rb1 and rb2) and islands (i1 and i2) as nodes in the graph. The bridges are represented by labeled arcs between nodes (b1, b2, . . . , b7).

Ioan Despi – Discrete Mathematics 9 of 31

slide-26
SLIDE 26

Bridges of K¨

  • nigsberg (solution)

Euler invented graph theory to solve this problem. We will use riverbanks (rb1 and rb2) and islands (i1 and i2) as nodes in the graph. The bridges are represented by labeled arcs between nodes (b1, b2, . . . , b7). We ignore bridge lengths, distances, aso.

Figure 5 : The graph of the city of K¨

  • ningsberg bridge system

Ioan Despi – Discrete Mathematics 9 of 31

slide-27
SLIDE 27

Bridges of K¨

  • nigsberg (solution)

The connect/3 predicate corresponds to an arc of the graph, asserting that two land pieces are connected by a particular bridge. As each bridge requires two facts, one for each direction in which the bridge may be crossed, we can use a rule connect(X, Y, Z) = connect(Y, X, Z). to specify that bridge Z can be crossed in both ways, from land piece X to land piece Y and vice-versa. Then we have the following facts: connect(i1, i2, b1). connect(rb1, i1, b2). connect(rb1, i1, b3). connect(rb1, i2, b4). connect(rb2, i1, b5). connect(rb2, i1, b6). connect(rb2, i2, b7). The predicate calculus representation is equivalent to the graph representation in that the connectedness is preserved. An algorithm can translate between the two representations with no loss of information.

Ioan Despi – Discrete Mathematics 10 of 31

slide-28
SLIDE 28

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible.

Ioan Despi – Discrete Mathematics 11 of 31

slide-29
SLIDE 29

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible. Euler defined the degree of a node – odd or even – depending on the number of arcs joining it to neighbouring nodes.

Ioan Despi – Discrete Mathematics 11 of 31

slide-30
SLIDE 30

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible. Euler defined the degree of a node – odd or even – depending on the number of arcs joining it to neighbouring nodes. If the degree of a node is odd, then the traveler could not exit the node without using a previously traveled arc.

Ioan Despi – Discrete Mathematics 11 of 31

slide-31
SLIDE 31

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible. Euler defined the degree of a node – odd or even – depending on the number of arcs joining it to neighbouring nodes. If the degree of a node is odd, then the traveler could not exit the node without using a previously traveled arc. So, with the exception of starting and ending nodes, the desired walk would have to leave each node exactly as often as it entered it, that is the nodes should have an even degree.

Ioan Despi – Discrete Mathematics 11 of 31

slide-32
SLIDE 32

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible. Euler defined the degree of a node – odd or even – depending on the number of arcs joining it to neighbouring nodes. If the degree of a node is odd, then the traveler could not exit the node without using a previously traveled arc. So, with the exception of starting and ending nodes, the desired walk would have to leave each node exactly as often as it entered it, that is the nodes should have an even degree. As Euler noticed, the graph should have exactly zero or two nodes of odd degree for the walk to be possible.

Ioan Despi – Discrete Mathematics 11 of 31

slide-33
SLIDE 33

Bridges of K¨

  • nigsberg (the truth)

The walk is impossible. Euler defined the degree of a node – odd or even – depending on the number of arcs joining it to neighbouring nodes. If the degree of a node is odd, then the traveler could not exit the node without using a previously traveled arc. So, with the exception of starting and ending nodes, the desired walk would have to leave each node exactly as often as it entered it, that is the nodes should have an even degree. As Euler noticed, the graph should have exactly zero or two nodes of odd degree for the walk to be possible. Bridges of K¨

  • nigsberg problem has four nodes of odd degree so the walk

is impossible.

Ioan Despi – Discrete Mathematics 11 of 31

slide-34
SLIDE 34

The Traveling Salesperson Problem [TSP]

Given a number of cities to be visited and the mileage between each pair of cities, find a minimum-mileage trip beginning and ending at city A that visits each of the other cities exactly once. Use the following sample mileage chart to create the corresponding state-space graph and (then) to find the solution. A B C D A – 30 50 40 B – 30 35 C – 25 D –

30 30 25 40 50 35 B A C D

Ioan Despi – Discrete Mathematics 12 of 31

slide-35
SLIDE 35

The Traveling Salesperson Problem (solution)

The search space contains (4 − 1)! = 3! = 6 paths:

A AB AC AD ABC ABCD ABCDA ABD ABDC ABDCA ACB ACBD ACBDA ACD ACDB ACDBA ADB ADBC ADBCA ADC ADCB ADCBA 30 50 40 30 35 30 25 35 25 25 25 35 35 30 30 40 50 40 30 50 30 125 140 155 140 155 125

Ioan Despi – Discrete Mathematics 13 of 31

slide-36
SLIDE 36

The Traveling Salesperson Problem (solution)

This is an example of touring problem. Because different paths to the same city represent distinct partial solutions, each state is identified not just as a city name but as a list of the cities visited so far. So, the initial state is (In A; visited A) and a typical intermediate state would be (In B; visited A, C, B). The goal test would check whether the agent is in A and all four cities have been visited. The desired solution is A – D – C – B – A or its reversal, A – B – C – D – A, with a total mileage of 125.

Ioan Despi – Discrete Mathematics 14 of 31

slide-37
SLIDE 37

Useful Definitions

Let G be a connected graph.

Ioan Despi – Discrete Mathematics 15 of 31

slide-38
SLIDE 38

Useful Definitions

Let G be a connected graph.

Eulerian Path.

A path that contains every edge of a connected graph exactly once, or A walk from one vertex to another, that passes all vertices of G and traverses exactly once every edge of G.

Ioan Despi – Discrete Mathematics 15 of 31

slide-39
SLIDE 39

Useful Definitions

Let G be a connected graph.

Eulerian Path.

A path that contains every edge of a connected graph exactly once, or A walk from one vertex to another, that passes all vertices of G and traverses exactly once every edge of G.

Eulerian Circuit.

An Eulerian path that starts and ends at the same vertex, or A circuit that includes all vertices and edges of a graph G, or A circuit passing through every edge just once (and every vertex at least

  • nce).

Ioan Despi – Discrete Mathematics 15 of 31

slide-40
SLIDE 40

Useful Definitions

Let G be a connected graph.

Eulerian Path.

A path that contains every edge of a connected graph exactly once, or A walk from one vertex to another, that passes all vertices of G and traverses exactly once every edge of G.

Eulerian Circuit.

An Eulerian path that starts and ends at the same vertex, or A circuit that includes all vertices and edges of a graph G, or A circuit passing through every edge just once (and every vertex at least

  • nce).

Eulerian Graph.

A graph which has an Eulerian circuit.

Ioan Despi – Discrete Mathematics 15 of 31

slide-41
SLIDE 41

Useful Definitions

Remember:

Ioan Despi – Discrete Mathematics 16 of 31

slide-42
SLIDE 42

Useful Definitions

Remember:

Ioan Despi – Discrete Mathematics 16 of 31

slide-43
SLIDE 43

Useful Definitions

Remember:

◮ An Eulerian circuit is a type of Eulerian path, but

a b c d e

Figure 6 : Eulerian circuit

a b d e

Figure 7 : Eulerian path

Ioan Despi – Discrete Mathematics 16 of 31

slide-44
SLIDE 44

Useful Definitions

Remember:

◮ An Eulerian circuit is a type of Eulerian path, but ◮ An Eulerian path is not necessarily an Eulerian circuit.

a b c d e

Figure 6 : Eulerian circuit

a b d e

Figure 7 : Eulerian path

Ioan Despi – Discrete Mathematics 16 of 31

slide-45
SLIDE 45

Useful Definitions

Remember:

◮ An Eulerian circuit is a type of Eulerian path, but ◮ An Eulerian path is not necessarily an Eulerian circuit.

The left graph (Figure 6) has an Eulerian cycle (circuit): a, c, d, e, c, b, a

a b c d e

Figure 6 : Eulerian circuit

a b d e

Figure 7 : Eulerian path

Ioan Despi – Discrete Mathematics 16 of 31

slide-46
SLIDE 46

Useful Definitions

Remember:

◮ An Eulerian circuit is a type of Eulerian path, but ◮ An Eulerian path is not necessarily an Eulerian circuit.

The left graph (Figure 6) has an Eulerian cycle (circuit): a, c, d, e, c, b, a The right graph (Figure 7) has an Eulerian path b, a, e, d, b, e

a b c d e

Figure 6 : Eulerian circuit

a b d e

Figure 7 : Eulerian path

Ioan Despi – Discrete Mathematics 16 of 31

slide-47
SLIDE 47

Euler’s Theorem

Theorem (Euler).

Let G be a connected graph.

1 G has an Eulerian circuit (i.e., is Eulerian) if and only if every vertex of G

has even degree.

Ioan Despi – Discrete Mathematics 17 of 31

slide-48
SLIDE 48

Euler’s Theorem

Theorem (Euler).

Let G be a connected graph.

1 G has an Eulerian circuit (i.e., is Eulerian) if and only if every vertex of G

has even degree.

2 G has an Eulerian path, but not an Eulerian circuit, if and only if G has

exactly two vertices of odd degree.

Ioan Despi – Discrete Mathematics 17 of 31

slide-49
SLIDE 49

Euler’s Theorem

Theorem (Euler).

Let G be a connected graph.

1 G has an Eulerian circuit (i.e., is Eulerian) if and only if every vertex of G

has even degree.

2 G has an Eulerian path, but not an Eulerian circuit, if and only if G has

exactly two vertices of odd degree.

◮ The Eulerian path in this case must start at any of the two ’odd-degree’

vertices and finish at the other one ’odd-degree’ vertex.

Ioan Despi – Discrete Mathematics 17 of 31

slide-50
SLIDE 50

Euler’s Theorem

Theorem (Euler).

Let G be a connected graph.

1 G has an Eulerian circuit (i.e., is Eulerian) if and only if every vertex of G

has even degree.

2 G has an Eulerian path, but not an Eulerian circuit, if and only if G has

exactly two vertices of odd degree.

◮ The Eulerian path in this case must start at any of the two ’odd-degree’

vertices and finish at the other one ’odd-degree’ vertex.

Ioan Despi – Discrete Mathematics 17 of 31

slide-51
SLIDE 51

Euler’s Theorem

Theorem (Euler).

Let G be a connected graph.

1 G has an Eulerian circuit (i.e., is Eulerian) if and only if every vertex of G

has even degree.

2 G has an Eulerian path, but not an Eulerian circuit, if and only if G has

exactly two vertices of odd degree.

◮ The Eulerian path in this case must start at any of the two ’odd-degree’

vertices and finish at the other one ’odd-degree’ vertex.

Proof.

We only consider the case (i). Euler proved necessity in 1736. Necessity is trivial: G Eulerian = ⇒ all vertices have even degree. Let C be an Eulerian (circuit) path of G and v an arbitrary vertex of

  • G. Then, each edge in C that enters v must be followed by an edge in

C that leaves v, hence the total number of edges incident at v must be even, therefore v has an even degree.

Ioan Despi – Discrete Mathematics 17 of 31

slide-52
SLIDE 52

Euler’s Theorem (cont.)

Proof.

In 1873 (137 years later), a young German mathematician, Carl Hierholzer published the proof of sufficiency. Sufficiency : all vertices have even degree = ⇒ G Eulerian Proof by induction. Let Sn be the statement that a connected graph of n vertices must be Eulerian if every vertex has even degree. for n = 1, G contains either a single vertex or a single vertex with loops. Hence, S1 is true, because an Eulerian circuit can be obtained by traversing all loops (if any) one by one. The smallest possible number of edges is 3 (i.e., a triangle) in the case of simple graphs, and 2 (i.e., a digon) in the case

  • f multigraphs. In both cases, the graph trivially contains

an Eulerian circuit.

Ioan Despi – Discrete Mathematics 18 of 31

slide-53
SLIDE 53

Euler’s Theorem (cont.)

Proof.

Assume Sk is true, that is Let H be a connected graph with ≤ k edges. If every vertex

  • f H has even degree, H contains an Eulerian circuit.

Let G be a graph with k + 1 edges, and every vertex has an even degree. Since there is no odd degree vertex, G cannot be a tree. Thus, G must contain a cycle C. We start with any vertex and choose a next vertex from all adjacent vertices in random order. We continues in this manner. After finite number of steps, we will end in the vertex we started with.

◮ If we traverse all edges, we build an Eulerian cycle, ◮ otherwise, consider a subgraph H obtained from the original graph by

deleting that cycle.

⋆ Each vertex of H has even degree. In the above left picture (Figure 6),

graph H might consist of vertices c, d, e.

⋆ The original graph and H must have one vertex in common. We start with

this vertex and repeat the procedure. We repeat all these until all edges are traversed.

Ioan Despi – Discrete Mathematics 19 of 31

slide-54
SLIDE 54

Euler’s Theorem (in other words. . . )

Proof.

Choose any starting vertex v, and follow a path of edges from that vertex until returning to v.

Ioan Despi – Discrete Mathematics 20 of 31

slide-55
SLIDE 55

Euler’s Theorem (in other words. . . )

Proof.

Choose any starting vertex v, and follow a path of edges from that vertex until returning to v. The even degree of all vertices ensures that, when the path enters another vertex w, there must be an unused edge leaving w.

Ioan Despi – Discrete Mathematics 20 of 31

slide-56
SLIDE 56

Euler’s Theorem (in other words. . . )

Proof.

Choose any starting vertex v, and follow a path of edges from that vertex until returning to v. The even degree of all vertices ensures that, when the path enters another vertex w, there must be an unused edge leaving w. Therefore, it is not possible to get stuck at any vertex other than v.

Ioan Despi – Discrete Mathematics 20 of 31

slide-57
SLIDE 57

Euler’s Theorem (in other words. . . )

Proof.

Choose any starting vertex v, and follow a path of edges from that vertex until returning to v. The even degree of all vertices ensures that, when the path enters another vertex w, there must be an unused edge leaving w. Therefore, it is not possible to get stuck at any vertex other than v. The walk formed in this way is a closed one, but may not cover all the vertices and edges of the initial graph.

Ioan Despi – Discrete Mathematics 20 of 31

slide-58
SLIDE 58

Euler’s Theorem (in other words. . . )

Proof.

Choose any starting vertex v, and follow a path of edges from that vertex until returning to v. The even degree of all vertices ensures that, when the path enters another vertex w, there must be an unused edge leaving w. Therefore, it is not possible to get stuck at any vertex other than v. The walk formed in this way is a closed one, but may not cover all the vertices and edges of the initial graph. As long as there exists a vertex v that belongs to the current tour but that has adjacent edges not part of the tour, start another trail from v, following unused edges until returning to v, and join the tour formed in this way to the previous tour.

Ioan Despi – Discrete Mathematics 20 of 31

slide-59
SLIDE 59

Examples

1 Due to the above Euler’s theorem, the seven bridge problem has no

solution, because all vertices (V = {i1, i2, rb1, rb2}) have odd degrees.

2 In the graph from Figure 8: v1 − e1 − v2 − e2 − v2 − e3 − v3 − e4 − v1 is

an Eulerian circuit.

3 The graph in Figure 9 has an Eulerian path but is not Eulerian.

v1 v2 v3 e1 e3 e4 e2

Figure 8 : Eulerian circuit Figure 9 : Eulerian path

4 K3 is an Eulerian graph, but K4 is not Eulerian. Ioan Despi – Discrete Mathematics 21 of 31

slide-60
SLIDE 60

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Ioan Despi – Discrete Mathematics 22 of 31

slide-61
SLIDE 61

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Hamiltonian Path.

A walk that includes every vertex of G exactly once.

Ioan Despi – Discrete Mathematics 22 of 31

slide-62
SLIDE 62

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Hamiltonian Path.

A walk that includes every vertex of G exactly once. An Hamiltonian path is therefore not a circuit.

Ioan Despi – Discrete Mathematics 22 of 31

slide-63
SLIDE 63

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Hamiltonian Path.

A walk that includes every vertex of G exactly once. An Hamiltonian path is therefore not a circuit. There are no known conditions which are both necessary and sufficient.

Ioan Despi – Discrete Mathematics 22 of 31

slide-64
SLIDE 64

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Hamiltonian Path.

A walk that includes every vertex of G exactly once. An Hamiltonian path is therefore not a circuit. There are no known conditions which are both necessary and sufficient. There are a few sufficient considitons.

Ioan Despi – Discrete Mathematics 22 of 31

slide-65
SLIDE 65

Hamiltonian Circuit

Hamiltonian Circuit.

A circuit that includes every vertex (except first/last vertex) of G exactly

  • nce.

A circuit that visits each vertex once without touching any vertex more than once. A cycle that traverses every vertex of a graph exactly once.

Hamiltonian Path.

A walk that includes every vertex of G exactly once. An Hamiltonian path is therefore not a circuit. There are no known conditions which are both necessary and sufficient. There are a few sufficient considitons. For a graph to have a Hamiltonian circuit, the degree of each vertex must be two or more.

Ioan Despi – Discrete Mathematics 22 of 31

slide-66
SLIDE 66

Examples

Notice that

◮ for an Euler path you may visit each vertex more than once and ◮ in a Hamilton path it is not necessary to travel every edge.

The best known algorithm for finding a Hamiltonian cycle has an exponential worst-case complexity. In the graph from Figure 8: v1 − e1 − v2 − e2 − v2 − e3 − v3 − e4 − v1 is an Eulerian circuit but not an Hamiltonian circuit. In the graph from Figure 8: v1 − e1 − v2 − e3 − v3 − e4 − v1 is a Hamiltonian circuit, but not an Eulerian circuit.

v1 v2 v3 e1 e3 e4 e2

Figure 10 : Eulerian circuit Figure 11 : Icosian puzzle, invented by Hamilton (1857)

Ioan Despi – Discrete Mathematics 23 of 31

slide-67
SLIDE 67

Examples (cont.)

Figure 12 is an Eulerian circuit but not an Hamiltonian circuit. Figure 13 is an Hamiltonian circuit but not an Eulerian circuit.

Figure 12 : Eulerian circuit but not Hamiltonian Figure 13 : Hamiltonian circuit, but not Eulerian

Ioan Despi – Discrete Mathematics 24 of 31

slide-68
SLIDE 68

Examples (cont.)

Pictures (a) and (b) have no nodes of odd degree and must, therefore, have an Euler circuit. A B H G I J N K L M F E C D (a) A B C D (b)

Ioan Despi – Discrete Mathematics 25 of 31

slide-69
SLIDE 69

Examples (cont.)

Pictures (a) and (b) have no nodes of odd degree and must, therefore, have an Euler circuit. For instance, the circuit B, C, D, A, C, A, B for picture (b). A B H G I J N K L M F E C D (a) A B C D (b)

Ioan Despi – Discrete Mathematics 25 of 31

slide-70
SLIDE 70

Examples (cont.)

Pictures (a) and (b) have no nodes of odd degree and must, therefore, have an Euler circuit. For instance, the circuit B, C, D, A, C, A, B for picture (b). Nnote that the A-C-A portion of the circuit can be traversed in either of two ways. A B H G I J N K L M F E C D (a) A B C D (b)

Ioan Despi – Discrete Mathematics 25 of 31

slide-71
SLIDE 71

Examples (cont.)

Pictures (c) and (d) have exactly two nodes of odd degree, thus they must contain an Euler path. A B (c) A D C E F (d) B

Ioan Despi – Discrete Mathematics 26 of 31

slide-72
SLIDE 72

Examples (cont.)

Pictures (c) and (d) have exactly two nodes of odd degree, thus they must contain an Euler path. For instance, A, B, D, E, C, A, F, C, B, E, F is an Euler path for picture (d). A B (c) A D C E F (d) B

Ioan Despi – Discrete Mathematics 26 of 31

slide-73
SLIDE 73

Examples (cont.)

Pictures (c) and (d) have exactly two nodes of odd degree, thus they must contain an Euler path. For instance, A, B, D, E, C, A, F, C, B, E, F is an Euler path for picture (d). It is impossible to find an Euler path that does not begin at A and terminate at F (or vie-versa). A B (c) A D C E F (d) B

Ioan Despi – Discrete Mathematics 26 of 31

slide-74
SLIDE 74

Examples (cont.)

Pictures (e) and (f) have four nodes of odd degree, and thus neither an Euler circuit nor an Euler path can be found on either. A B D E (e) A B C D (f)

Ioan Despi – Discrete Mathematics 27 of 31

slide-75
SLIDE 75

Examples (cont.)

Pictures (e) and (f) have four nodes of odd degree, and thus neither an Euler circuit nor an Euler path can be found on either. Picture (f) is actually the representation of the K¨

  • nigsberg bridges

problem. A B D E (e) A B C D (f)

Ioan Despi – Discrete Mathematics 27 of 31

slide-76
SLIDE 76

Examples (cont.)

For the travelling salesman problem, we need to find all the Hamiltonian circuits for the graph, calculate the respective total distance and then choose the shortest route. route total distance A → B → C → D → A 30 + 30 + 25 + 40 = 125 A → B → D → C → A 140 A → C → B → D → A 155 A → C → D → B → A 140 A → D → B → C → A 155 A → D → C → B → A 125 Hence the best route is either ABCDA or ADCBA.

Ioan Despi – Discrete Mathematics 28 of 31

slide-77
SLIDE 77

Fleury’s Algorithm Finding an Eulerian Path or Circuit

Fleury’s Algorithm

1 Check if the graph is connected and it has either 0 or 2 odd vertices.

Reject otherwise.

Ioan Despi – Discrete Mathematics 29 of 31

slide-78
SLIDE 78

Fleury’s Algorithm Finding an Eulerian Path or Circuit

Fleury’s Algorithm

1 Check if the graph is connected and it has either 0 or 2 odd vertices.

Reject otherwise.

2 If there are 0 odd vertices, pick any vertex to start.

If there are 2 odd vertices, start at one of them. Call it vstart.

Ioan Despi – Discrete Mathematics 29 of 31

slide-79
SLIDE 79

Fleury’s Algorithm Finding an Eulerian Path or Circuit

Fleury’s Algorithm

1 Check if the graph is connected and it has either 0 or 2 odd vertices.

Reject otherwise.

2 If there are 0 odd vertices, pick any vertex to start.

If there are 2 odd vertices, start at one of them. Call it vstart.

3 While the graph contains at least one edge: Ioan Despi – Discrete Mathematics 29 of 31

slide-80
SLIDE 80

Fleury’s Algorithm Finding an Eulerian Path or Circuit

Fleury’s Algorithm

1 Check if the graph is connected and it has either 0 or 2 odd vertices.

Reject otherwise.

2 If there are 0 odd vertices, pick any vertex to start.

If there are 2 odd vertices, start at one of them. Call it vstart.

3 While the graph contains at least one edge: 1 If you have a choice, always pick an edge that is not a bridge. Ioan Despi – Discrete Mathematics 29 of 31

slide-81
SLIDE 81

Fleury’s Algorithm Finding an Eulerian Path or Circuit

Fleury’s Algorithm

1 Check if the graph is connected and it has either 0 or 2 odd vertices.

Reject otherwise.

2 If there are 0 odd vertices, pick any vertex to start.

If there are 2 odd vertices, start at one of them. Call it vstart.

3 While the graph contains at least one edge: 1 If you have a choice, always pick an edge that is not a bridge. 2 Traverse that edge, and remove it from G. Ioan Despi – Discrete Mathematics 29 of 31

slide-82
SLIDE 82

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed.

Ioan Despi – Discrete Mathematics 30 of 31

slide-83
SLIDE 83

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed. Then either v must have an odd degree, or G is not a connected graph to begin with.

Ioan Despi – Discrete Mathematics 30 of 31

slide-84
SLIDE 84

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed. Then either v must have an odd degree, or G is not a connected graph to begin with. Both of these cases are impossible due to our first check. This is a contradiction.

Ioan Despi – Discrete Mathematics 30 of 31

slide-85
SLIDE 85

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed. Then either v must have an odd degree, or G is not a connected graph to begin with. Both of these cases are impossible due to our first check. This is a contradiction. Note that, when the algorithm terminates, we must return to vstart because every vertex has an even degree.

Ioan Despi – Discrete Mathematics 30 of 31

slide-86
SLIDE 86

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed. Then either v must have an odd degree, or G is not a connected graph to begin with. Both of these cases are impossible due to our first check. This is a contradiction. Note that, when the algorithm terminates, we must return to vstart because every vertex has an even degree. Furthermore, the edge removal operation guarantees that each edge is visited exactly once.

Ioan Despi – Discrete Mathematics 30 of 31

slide-87
SLIDE 87

Proof of Correctness

To see that this algorithm terminates, suppose we are stuck at some vertex v before all the edges are removed. Then either v must have an odd degree, or G is not a connected graph to begin with. Both of these cases are impossible due to our first check. This is a contradiction. Note that, when the algorithm terminates, we must return to vstart because every vertex has an even degree. Furthermore, the edge removal operation guarantees that each edge is visited exactly once. Therefore, the discovered tour is an Eulerian circuit.

Ioan Despi – Discrete Mathematics 30 of 31

slide-88
SLIDE 88

Example

Find an Eulerian path for the grapth in Figure 14

v1 v2 v3 v4 v6 v7 e1 e2 e3 e4 e5 e7 e8 e9 v5 e6

Figure 14 : Fleury’s Algorithm

We start at v5 because δ(v5) is odd.

Ioan Despi – Discrete Mathematics 31 of 31

slide-89
SLIDE 89

Example

Find an Eulerian path for the grapth in Figure 14

v1 v2 v3 v4 v6 v7 e1 e2 e3 e4 e5 e7 e8 e9 v5 e6

Figure 14 : Fleury’s Algorithm

We start at v5 because δ(v5) is odd. We can’t choose edge e5 to travel next because the removal of e5 breaks G into two disconnected parts.

Ioan Despi – Discrete Mathematics 31 of 31

slide-90
SLIDE 90

Example

Find an Eulerian path for the grapth in Figure 14

v1 v2 v3 v4 v6 v7 e1 e2 e3 e4 e5 e7 e8 e9 v5 e6

Figure 14 : Fleury’s Algorithm

We start at v5 because δ(v5) is odd. We can’t choose edge e5 to travel next because the removal of e5 breaks G into two disconnected parts. We can choose e6 or e7 or e9.; we choose e6.

Ioan Despi – Discrete Mathematics 31 of 31

slide-91
SLIDE 91

Example

Find an Eulerian path for the grapth in Figure 14

v1 v2 v3 v4 v6 v7 e1 e2 e3 e4 e5 e7 e8 e9 v5 e6

Figure 14 : Fleury’s Algorithm

We start at v5 because δ(v5) is odd. We can’t choose edge e5 to travel next because the removal of e5 breaks G into two disconnected parts. We can choose e6 or e7 or e9.; we choose e6. One Eulerian path is v5

e6

− → v5

e7

− → v6

e8

− → v7

e9

− → v5

e5

− → v4

e3

− → v3

e2

− → v2

e1

− → v1

e4

− → v4

Ioan Despi – Discrete Mathematics 31 of 31