41
How to Paint Your Way out of a Maze Prof. Joshua Holden, Rose-Hulman Inst. of Tech. Joint work with Lana Holden How to Paint Your Way out of a Maze – p. 1/3

How to Paint Your Way out of a Maze

Embed Size (px)

DESCRIPTION

Many people don't realize that what we now call "algorithm design" actually dates back to the ancient Greeks! Of course, if you think about it, there's always the "Euclidean Algorithm". A more dubious example might be Theseus's use of a ball of string to solve the "Labyrinth Problem". (Google "Theseus, Labyrinth, string".) Solutions to this problem got a lot less dubious after graph theory was invited, since a graph turns out to be a good way of representing a maze mathematically. We will examine the classical solutions to this problem, and then throw in a twist --- a Twisted Painting Machine that puts restrictions on which paths we can take to explore the maze. Applications to sewing may also appear, depending on the presence of audience interest and string.

Citation preview

Page 1: How to Paint Your Way out of a Maze

How to Paint Your Way out of aMaze

Prof. Joshua Holden, Rose-Hulman Inst. of Tech.Joint work with Lana Holden

How to Paint Your Way out of a Maze – p. 1/30

Page 2: How to Paint Your Way out of a Maze

Graphs and Digraphs

Definition A (loop-free) graph is a set of vertices,V , and a set of edges, E, where each edge isan unordered pair of distinct vertices.

Definition A (loop-free) digraph is a set ofvertices, V , and a set of edges, E, whereeach edge is an ordered pair of distinctvertices.(The order is thought of as indicating a“direction”.)

How to Paint Your Way out of a Maze – p. 2/30

Page 3: How to Paint Your Way out of a Maze

Associating Graphs and Digraphs

An graph may be associated to a digraph byforgetting about the ordering of the pairs.A digraph may be associated to a graph byincluding both possible orders (or directions)of each edge.

How to Paint Your Way out of a Maze – p. 3/30

Page 4: How to Paint Your Way out of a Maze

Walks

Definition A walk on a graph is a finite alternatingsequence of vertices and edgesx0, e1, x1, . . . , en, xn where each ei = {xi−1, xi}.

Definition A graph is connected if there is a walkbetween any two vertices.

Definition A directed walk on a digraph is a finitealternating sequence of vertices and edgesx0, e1, x1, . . . , en, xn where eachei = (xi−1, xi).

How to Paint Your Way out of a Maze – p. 4/30

Page 5: How to Paint Your Way out of a Maze

Connected and Strongly Connected

Definition A digraph is strongly connected if thereis a directed walk between any two vertices.

Lemma If a digraph is strongly connected thenthe associated graph is connected.

Lemma If a graph is connected then theassociated digraph is strongly connected.

How to Paint Your Way out of a Maze – p. 5/30

Page 6: How to Paint Your Way out of a Maze

Trails and Circuits

Definition A directed trail is a directed walk whereno edge is repeated. (Although vertices maybe.)

Definition A directed circuit is a directed trailwhere x0 = xn.

Definition An Eulerian circuit of a digraph is adirected circuit which includes all of the edgesof the digraph.

Definition A digraph is Eulerian if it has anEulerian circuit.

How to Paint Your Way out of a Maze – p. 6/30

Page 7: How to Paint Your Way out of a Maze

Degrees

Definition For each vertex v of a digraph, the outdegree of v is the number of edges with v asthe starting point.

Definition For each vertex v of a digraph, the indegree of v is the number of edges with v asthe ending point.

How to Paint Your Way out of a Maze – p. 7/30

Page 8: How to Paint Your Way out of a Maze

Eulerian Graphs

Theorem A directed graph is Eulerian if and only ifit is strongly connected and the in degree ofeach vertex is equal to the out degree.

Lemma The digraph associated to a graph hasthe in degree of each vertex equal to the outdegree.

Corollary The digraph associated to a graph isEulerian if and only if the original graph isconnected.

How to Paint Your Way out of a Maze – p. 8/30

Page 9: How to Paint Your Way out of a Maze

Holbeinian Graphs

Definition A digraph is symmetric if it is thedigraph associated to some graph.

Definition If x0, e1, x1, . . . , en, xn is a directed trailon a digraph, we say that the parity of eachedge ei is the parity of i.

Definition An Holbeinian circuit of a symmetricdigraph is an Eulerian circuit where all edges(x, y) and (y, x) have opposite parities.

Definition A symmetric digraph is Holbeinian if ithas an Holbeinian circuit.

How to Paint Your Way out of a Maze – p. 9/30

Page 10: How to Paint Your Way out of a Maze

Theorem 1

Theorem 1 A symmetric digraph is Holbeinian ifand only if it is strongly connected.

Corollary A symmetric digraph is Holbeinian ifand only if the associated graph is connected.

How to Paint Your Way out of a Maze – p. 10/30

Page 11: How to Paint Your Way out of a Maze

Proof of Theorem 1

Let G be the symmetric digraph. If G has aHolbeinian circuit, then it must pass throughevery vertex. Thus for any two vertices, there is adirected walk from one to the other, so G isstrongly connected.Now assume G is strongly connected, and let Gu

be the associated graph. Let V the vertices ofGu, and E the edges. If E has only one edge{x, y}, then x, (x, y), y, (y, x), x is a Holbeiniancircuit of G.

How to Paint Your Way out of a Maze – p. 11/30

Page 12: How to Paint Your Way out of a Maze

Proof, continued

By way of induction, suppose the result is true ifE has less than n edges and that E has n edges.Let {x, y} be any edge of E. Let H be thedigraph obtained from G by removing the edges(x, y) and (y, x), and also either vertex x or y ifthere are no other edges going in or out. Noweither H is still strongly connected, or it is dividedinto two strongly connected pieces, one of whichcontains x and the other y.

How to Paint Your Way out of a Maze – p. 12/30

Page 13: How to Paint Your Way out of a Maze

Proof, continued

If H is still strongly connected, it has aHolbeinian circuit. A Holbeinian circuit of G isconstructed by following the Holbeinian circuit ofH until the vertex x is reached, then followingx, (x, y), y, (y, x), x, then finishing the Holbeiniancircuit of H. The detour of length 2 does notaffect the parity of any of the edges in the circuitof H.

How to Paint Your Way out of a Maze – p. 13/30

Page 14: How to Paint Your Way out of a Maze

Proof, continued

If H is no longer strongly connected, each piecehas a Holbeinian circuit. Let the pieces be H1

and H2, with associated graphs Hu1 and Hu

2 andassociated undirected edge sets E1 and E2. AHolbeinian circuit of G is constructed by followingthe Holbeinian circuit of H1 until the vertex x isreached, then following x, (x, y), y, then followingthe Holbeinian circuit of H2 back to y, thenfollowing y, (y, x), x, and finally finishing theHolbeinian circuit of H. The detour of length2 + 2|E2| does not affect the parity of any of theedges in the Holbeinian circuit of H1. 2

How to Paint Your Way out of a Maze – p. 14/30

Page 15: How to Paint Your Way out of a Maze

Multigraphs

Definition A (loop-free) multigraph is a set ofvertices, V , and a multiset of edges, E, whereeach edge is an unordered pair of distinctvertices.(A pair of vertices may have more than oneedge between them.)

Definition A pair of vertices has multiplicity n ifthere are exactly n edges between them.

Definition A multigraph has multiplicity n if everypair of vertices has multiplicity n.

How to Paint Your Way out of a Maze – p. 15/30

Page 16: How to Paint Your Way out of a Maze

Graphs and Multigraphs

A graph may be associated to a multigraph byforgetting about the multiplicity of the edges.A multigraph of multiplicity n may beassociated to a graph by giving every edgemultiplicity n.

How to Paint Your Way out of a Maze – p. 16/30

Page 17: How to Paint Your Way out of a Maze

Aragonian Graphs

Definition For each vertex v of a multigraph, thedegree of v is the number of edges with v asone endpoint.

Definition An Aragonian circuit of a multigraph ofmultiplicity 2 is an Eulerian circuit where thetwo edges {x, y} are both traversed in theorder x, {x, y}, y and are traversed withopposite parities.

Definition A multigraph of multiplicity 2 isAragonian if it has an Aragonian circuit.

How to Paint Your Way out of a Maze – p. 17/30

Page 18: How to Paint Your Way out of a Maze

What Graphs Are Aragonian?

Theorem 2 A multigraph of multiplicity 2 isAragonian if and only if it is connected, it hasa circuit of odd length, and every vertex hasdegree divisible by 4.

Corollary A multigraph of multiplicity 2 isAragonian if and only if the associated graphis connected, has a circuit of odd length, andevery vertex has even degree.

How to Paint Your Way out of a Maze – p. 18/30

Page 19: How to Paint Your Way out of a Maze

Alternatively. . .

Theorem A graph is Eulerian if and only if it isconnected and every vertex has even degree.

Corollary A multigraph of multiplicity 2 isAragonian if and only if the associated graphis Eulerian and has a circuit of odd length.

How to Paint Your Way out of a Maze – p. 19/30

Page 20: How to Paint Your Way out of a Maze

Proof of Theorem 2

Let G be the multigraph. If G has an Aragoniancircuit, then it must pass through every vertex.Thus for any two vertices, there is a walk fromone to the other, so G is connected.For any vertex v of G other than the startingvertex, each time the circuit comes to v then itdeparts from v. Thus the circuit has traversedtwo (new) edges with v as an endpoint. Since itmust do this twice for each edge, the degree of v

must be a multiple of 4. (For the starting vertex,consider the first edge of the circuit and the lastedge.)

How to Paint Your Way out of a Maze – p. 20/30

Page 21: How to Paint Your Way out of a Maze

Proof, continued

To show that G has a circuit of odd length,consider the first edge {x, y} to appear twice inthe Aragonian circuit. Since it must appear withopposite parities each time, the part of the circuitwhich includes the first occurrence of {x, y} andstops just short of the second occurrence of{x, y} will be a circuit of odd length.

How to Paint Your Way out of a Maze – p. 21/30

Page 22: How to Paint Your Way out of a Maze

Proof, continued

Now assume G is connected, has a circuit of oddlength, and every vertex has degree divisible by4. Let V the vertices of G, and E the edges. If E

has only three distinct edges {x, y}, {y, z}, {z, x}then

x, {x, y}, y, {y, z}, z, {z, x}, x,

{x, y}, y, {y, z}, z, {z, x}, x

is an Aragonian circuit of G.

How to Paint Your Way out of a Maze – p. 22/30

Page 23: How to Paint Your Way out of a Maze

Proof, continued

By way of induction, suppose the result is true ifE has less than n edges and that E has n edges.We know that G has a circuit of odd length; call ifC. If the circuit contains a copy of every edge inE, then we are done; simply follow the circuit C

twice. If not, let K be the sub-multigraph of G

obtained by removing the edges in C, and alsoany vertices which are left without edges going inor out. K has all vertices of degree a multiple of4, but it may not still be connected. However,each component of K is connected and itsassociated graph has an Eulerian circuit.

How to Paint Your Way out of a Maze – p. 23/30

Page 24: How to Paint Your Way out of a Maze

Proof, continued

We construct an Aragonian circuit on K byfollowing the circuit C until we arrive at a vertexx1 which is on the Euler circuit of a component ofK. If K has an odd number of edges, we followthis Eulerian circuit twice. Otherwise we follow itonce. In either case, the detours do not changethe parities of the edges of C.When we arrive back at the first edge of C, wehave switched parities, since C has an oddnumber of edges. We follow C again, this timeonly traversing the even components of K. Onceagain, the detours do not change the parities.

How to Paint Your Way out of a Maze – p. 24/30

Page 25: How to Paint Your Way out of a Maze

Trémaux’s Algorithm

Suppose we have a strongly connectedsymmetric digraph.1. Start at an arbitrary vertex x0.2. Proceed along any edge.

How to Paint Your Way out of a Maze – p. 25/30

Page 26: How to Paint Your Way out of a Maze

Trémaux’s Algorithm, continued

3. At each later step, suppose we have justtraversed an edge (x, y) and arrived at avertex y.

(a) If we have not visited y before:i. If there is an edge leaving y other than

(y, x), proceed along any such edge.ii. If there are no such edges, turn back

along (y, x).

How to Paint Your Way out of a Maze – p. 26/30

Page 27: How to Paint Your Way out of a Maze

Trémaux’s Algorithm, continued

3. (continued)(b) If we have visited y before:

i. If we have not traversed (y, x), turn backalong (y, x).

ii. If we have traversed (y, x):A. If there is an edge (y, z) for which

neither (y, z) nor (z, y) has beentraversed, proceed along any suchedge.

B. If every edge (z, y) has been traversedbut there is an edge (y, z) which hasnot been traversed, proceed along anysuch edge.

C. If every edge (y, z) has been traversed,terminate the algorithm.

How to Paint Your Way out of a Maze – p. 27/30

Page 28: How to Paint Your Way out of a Maze

Facts About Trémaux’s Algorithm

Lemma Trémaux’s algorithm traverses no directededge twice.

Proof Clear from the rules.Lemma Trémaux’s algorithm terminates at the

initial vertex.Proof (“by net flow”) At each vertex y other than x0

we have come in one more time than we havegone out, so we always have at least one wayout.

How to Paint Your Way out of a Maze – p. 28/30

Page 29: How to Paint Your Way out of a Maze

More Facts

Lemma Trémaux’s algorithm traverses no pair ofdirected edges in only one direction.

Proof Suppose (x, y) is the last edge traversedsuch that (y, x) is not traversed. This is thefirst visit to y, otherwise we would traverse(y, x) immediately. So we leave along (y, z).But then by net flow there is always anotheredge leaving y and not returning, whichcontradicts (x, y) being the last such edge.

How to Paint Your Way out of a Maze – p. 29/30

Page 30: How to Paint Your Way out of a Maze

Tremaux’s Algorithm Traverses

Theorem Tremaux’s algorithm traverses every directed edgeexactly once.

Proof We know that every pair of directed edges which is tra-versed is traversed in both directions. Suppose there issome (x, y) and (y, x) which are not traversed. Be-cause the graph is connected we can pick the pair sothat y is visited. Now y cannot be the terminating vertexbecause we can leave y along (y, x). Suppose (y, z)is the last edge leaving y. The edge (z, y) must havebeen traversed earlier, since it is traversed at some pointand we are not coming back to y. But then we did not fol-low the algorithm because we should have used (y, x)instead of (y, z) to leave y.

29-1

Page 31: How to Paint Your Way out of a Maze

Tremaux’s Algorithm and Parity

Theorem 3 Tremaux’s algorithm traverses (x, y) and (y, x)with opposite parity.

Proof Suppose (x, y) and (y, x) are traversed with the sameparity, (x, y) before (y, x), and (x, y) is the last such.The edge (x, y) must visit y for the first time; otherwisewe would immediately turn back along (y, x) and theparity would be opposite. When we do traverse (y, x),all of the edges (z, y) must have been traversed. Butthen by net flow, all of the edges (y, z) also must havebeen traversed.

Now “net flow with parity” also requires that the num-ber of edges going in with even parity equals the num-ber of edges going out with odd parity and the numberof edges going in with odd parity equals the number ofedges going out with even parity. But then since (y, x)is the only edge left when it is traversed, it must be tra-versed with opposite parity from (x, y).

29-2

Page 32: How to Paint Your Way out of a Maze

A Holbeinian Circuit!

Corollary Tremaux’s algorithm produces a Holbeinian circuitof the digraph.

29-3

Page 33: How to Paint Your Way out of a Maze

Tarry’s Algorithm (with parity)Suppose we have a strongly connected symmetric digraph.

1. Start at an arbitrary vertex x0.

2. Proceed along any edge.

3. At each later step, suppose we have arrived at a ver-tex y. If y is not x0, let (x1, y) be the edge that firstreached y (“entry edge”).

(a) If there is an edge (y, z) other than (y, x1) whichhas not been traversed (and such that (z, y) ei-ther has not been traversed or was traversed withparity opposite the current parity) proceed alongany such edge.

29-4

Page 34: How to Paint Your Way out of a Maze

Tarry’s Algorithm, continued

3. (continued)

(b) If every edge (y, z) other than (y, x1) has beentraversed (or (z, y) was traversed with the cur-rent parity), leave along (y, x1) (“reverse of entryedge”) (if (x1, y) was traversed with parity oppo-site the current parity).

(c) If there are no allowed moves as above, terminatethe algorithm.

29-5

Page 35: How to Paint Your Way out of a Maze

Facts About Tarry’s Algorithm

Lemma Tarry’s algorithm (with parity) traverses no directededge twice.

Proof Clear from the rules.

Lemma Tarry’s algorithm (with parity) terminates at the initialvertex.

Proof (“by net flow with parity”) At each vertex y other thanx0 we have come in one more time than we have goneout, so we always have at least one way out with oppo-site parity to the way we came in.

29-6

Page 36: How to Paint Your Way out of a Maze

More Facts

Lemma Tarry’s algorithm (with parity) visits every vertex, andleaves it along the reverse of its entry edge.

Proof Let U be the set of vertices that are visited and leftalong the reverse of the entry edge, plus x0. Let V

be all the other vertices. Since the graph is connected,if V is not empty, we can choose (u, v) such that u isin U and v is in V and, if v is visited, then (u, v) is theentry edge.

Now (v, u) is never traversed, so by net flow with parity,there is some (u, z) which is never traversed and suchthat (z, u) is traversed with opposite parity from (u, v).But then we cannot have left u by the entry edge, be-cause by net flow with parity you cannot have exhaustedall the edges with the opposite parity as (z, u) withoutfollowing (z, u).

29-7

Page 37: How to Paint Your Way out of a Maze

Tarry’s Algorithm and Parity

Theorem 4 Tarry’s algorithm (with parity) traverses every di-rected edge exactly once, and traverses (x, y) and (y, x)with opposite parity.

Proof The algorithm can terminate only when it has left x0 byevery possible edge and thus returned by every possi-ble edge; net flow with parity ensures that an edge ofthe correct parity is always available. But every othervertex v must be left by the reverse of its entry edge,and thus it must first leave and return by every possibleedge; net flow with parity again applies. The rules en-sure that (x, y) and (y, x) are traversed with oppositeparity.

29-8

Page 38: How to Paint Your Way out of a Maze

Another Holbeinian Circuit

Corollary Tarry’s algorithm (with parity) produces a Holbeiniancircuit of the digraph.

29-9

Page 39: How to Paint Your Way out of a Maze

A False Conjecture

Conjecture Every Holbeinian circuit can be produced from Tremaux’salgorithm.

Counterexample

29-10

Page 40: How to Paint Your Way out of a Maze

Another False Conjecture

Theorem 5 Every circuit which can be produced from Tremaux’salgorithm can be produced from Tarry’s algorithm (withparity).

Conjecture Every Holbeinian circuit can be produced from Tarry’salgorithm.

Counterexample

Conjecture ?

29-11

Page 41: How to Paint Your Way out of a Maze

Thanks, and happy painting!

How to Paint Your Way out of a Maze – p. 30/30