<s>
A	O
maze-solving	B-Algorithm
algorithm	I-Algorithm
is	O
an	O
automated	O
method	O
for	O
solving	O
a	O
maze	B-Application
.	O
</s>
<s>
The	O
random	O
mouse	O
,	O
wall	O
follower	O
,	O
Pledge	O
,	O
and	O
Trémaux	O
's	O
algorithms	O
are	O
designed	O
to	O
be	O
used	O
inside	O
the	O
maze	B-Application
by	O
a	O
traveler	O
with	O
no	O
prior	O
knowledge	O
of	O
the	O
maze	B-Application
,	O
whereas	O
the	O
dead-end	O
filling	O
and	O
shortest	O
path	O
algorithms	O
are	O
designed	O
to	O
be	O
used	O
by	O
a	O
person	O
or	O
computer	O
program	O
that	O
can	O
see	O
the	O
whole	O
maze	B-Application
at	O
once	O
.	O
</s>
<s>
Mazes	B-Application
containing	O
no	O
loops	O
are	O
known	O
as	O
"	O
simply	O
connected	O
"	O
,	O
or	O
"	O
perfect	O
"	O
mazes	B-Application
,	O
and	O
are	O
equivalent	O
to	O
a	O
tree	O
in	O
graph	O
theory	O
.	O
</s>
<s>
Maze-solving	B-Algorithm
algorithms	I-Algorithm
are	O
closely	O
related	O
to	O
graph	O
theory	O
.	O
</s>
<s>
Intuitively	O
,	O
if	O
one	O
pulled	O
and	O
stretched	O
out	O
the	O
paths	O
in	O
the	O
maze	B-Application
in	O
the	O
proper	O
way	O
,	O
the	O
result	O
could	O
be	O
made	O
to	O
resemble	O
a	O
tree	O
.	O
</s>
<s>
This	O
is	O
a	O
trivial	O
method	O
that	O
can	O
be	O
implemented	O
by	O
a	O
very	O
unintelligent	O
robot	B-Algorithm
or	O
perhaps	O
a	O
mouse	O
.	O
</s>
<s>
The	O
best-known	O
rule	O
for	O
traversing	O
mazes	B-Application
is	O
the	O
wall	O
follower	O
,	O
also	O
known	O
as	O
either	O
the	O
left-hand	O
rule	O
or	O
the	O
right-hand	O
rule	O
.	O
</s>
<s>
If	O
the	O
maze	B-Application
is	O
simply	O
connected	O
,	O
that	O
is	O
,	O
all	O
its	O
walls	O
are	O
connected	O
together	O
or	O
to	O
the	O
maze	B-Application
's	O
outer	O
boundary	O
,	O
then	O
by	O
keeping	O
one	O
hand	O
in	O
contact	O
with	O
one	O
wall	O
of	O
the	O
maze	B-Application
the	O
solver	O
is	O
guaranteed	O
not	O
to	O
get	O
lost	O
and	O
will	O
reach	O
a	O
different	O
exit	O
if	O
there	O
is	O
one	O
;	O
otherwise	O
,	O
the	O
algorithm	O
will	O
return	O
to	O
the	O
entrance	O
having	O
traversed	O
every	O
corridor	O
next	O
to	O
that	O
connected	O
section	O
of	O
walls	O
at	O
least	O
once	O
.	O
</s>
<s>
The	O
algorithm	O
is	O
a	O
depth-first	B-Algorithm
in-order	O
tree	B-Algorithm
traversal	I-Algorithm
.	O
</s>
<s>
To	O
further	O
this	O
idea	O
,	O
notice	O
that	O
by	O
grouping	O
together	O
connected	O
components	O
of	O
the	O
maze	B-Application
walls	O
,	O
the	O
boundaries	O
between	O
these	O
are	O
precisely	O
the	O
solutions	O
,	O
even	O
if	O
there	O
is	O
more	O
than	O
one	O
solution	O
(	O
see	O
figures	O
on	O
the	O
right	O
)	O
.	O
</s>
<s>
If	O
the	O
maze	B-Application
is	O
not	O
simply-connected	O
(	O
i.e.	O
</s>
<s>
Another	O
concern	O
is	O
that	O
care	O
should	O
be	O
taken	O
to	O
begin	O
wall-following	O
at	O
the	O
entrance	O
to	O
the	O
maze	B-Application
.	O
</s>
<s>
If	O
the	O
maze	B-Application
is	O
not	O
simply-connected	O
and	O
one	O
begins	O
wall-following	O
at	O
an	O
arbitrary	O
point	O
inside	O
the	O
maze	B-Application
,	O
one	O
could	O
find	O
themselves	O
trapped	O
along	O
a	O
separate	O
wall	O
that	O
loops	O
around	O
on	O
itself	O
and	O
containing	O
no	O
entrances	O
or	O
exits	O
.	O
</s>
<s>
Because	O
wall-following	O
will	O
always	O
lead	O
you	O
back	O
to	O
where	O
you	O
started	O
,	O
if	O
you	O
come	O
across	O
your	O
starting	O
point	O
a	O
second	O
time	O
,	O
you	O
can	O
conclude	O
the	O
maze	B-Application
is	O
not	O
simply-connected	O
,	O
and	O
you	O
should	O
switch	O
to	O
an	O
alternative	O
wall	O
not	O
yet	O
followed	O
.	O
</s>
<s>
Wall-following	O
can	O
be	O
done	O
in	O
3D	O
or	O
higher-dimensional	O
mazes	B-Application
if	O
its	O
higher-dimensional	O
passages	O
can	O
be	O
projected	O
onto	O
the	O
2D	O
plane	O
in	O
a	O
deterministic	O
manner	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
in	O
a	O
3D	O
maze	B-Application
"	O
up	O
"	O
passages	O
can	O
be	O
assumed	O
to	O
lead	O
Northwest	O
,	O
and	O
"	O
down	O
"	O
passages	O
can	O
be	O
assumed	O
to	O
lead	O
southeast	O
,	O
then	O
standard	O
wall	O
following	O
rules	O
can	O
apply	O
.	O
</s>
<s>
Disjoint	O
(	O
where	O
walls	O
are	O
not	O
connected	O
to	O
the	O
outer	O
boundary/boundary	O
is	O
not	O
closed	O
)	O
mazes	B-Application
can	O
be	O
solved	O
with	O
the	O
wall	O
follower	O
method	O
,	O
so	O
long	O
as	O
the	O
entrance	O
and	O
exit	O
to	O
the	O
maze	B-Application
are	O
on	O
the	O
outer	O
walls	O
of	O
the	O
maze	B-Application
.	O
</s>
<s>
If	O
however	O
,	O
the	O
solver	O
starts	O
inside	O
the	O
maze	B-Application
,	O
it	O
might	O
be	O
on	O
a	O
section	O
disjoint	O
from	O
the	O
exit	O
,	O
and	O
wall	O
followers	O
will	O
continually	O
go	O
around	O
their	O
ring	O
.	O
</s>
<s>
This	O
algorithm	O
allows	O
a	O
person	O
with	O
a	O
compass	O
to	O
find	O
their	O
way	O
from	O
any	O
point	O
inside	O
to	O
an	O
outer	O
exit	O
of	O
any	O
finite	O
two-dimensional	O
maze	B-Application
,	O
regardless	O
of	O
the	O
initial	O
position	O
of	O
the	O
solver	O
.	O
</s>
<s>
However	O
,	O
this	O
algorithm	O
will	O
not	O
work	O
in	O
doing	O
the	O
reverse	O
,	O
namely	O
finding	O
the	O
way	O
from	O
an	O
entrance	O
on	O
the	O
outside	O
of	O
a	O
maze	B-Application
to	O
some	O
end	O
goal	O
within	O
it	O
.	O
</s>
<s>
Trémaux	O
's	O
algorithm	O
,	O
invented	O
by	O
Charles	O
Pierre	O
Trémaux	O
,	O
is	O
an	O
efficient	O
method	O
to	O
find	O
the	O
way	O
out	O
of	O
a	O
maze	B-Application
that	O
requires	O
drawing	O
lines	O
on	O
the	O
floor	O
to	O
mark	O
a	O
path	O
,	O
and	O
is	O
guaranteed	O
to	O
work	O
for	O
all	O
mazes	B-Application
that	O
have	O
well-defined	O
passages	O
,	O
but	O
it	O
is	O
not	O
guaranteed	O
to	O
find	O
the	O
shortest	O
route	O
.	O
</s>
<s>
This	O
rule	O
also	O
applies	O
if	O
you	O
're	O
just	O
starting	O
in	O
the	O
middle	O
of	O
the	O
maze	B-Application
and	O
there	O
are	O
no	O
marked	O
entrances	O
at	O
all	O
.	O
</s>
<s>
The	O
"	O
turn	O
around	O
and	O
return	O
"	O
rule	O
effectively	O
transforms	O
any	O
maze	B-Application
with	O
loops	O
into	O
a	O
simply	O
connected	O
one	O
;	O
whenever	O
we	O
find	O
a	O
path	O
that	O
would	O
close	O
a	O
loop	O
,	O
we	O
treat	O
it	O
as	O
a	O
dead	O
end	O
and	O
return	O
.	O
</s>
<s>
Without	O
this	O
rule	O
,	O
it	O
is	O
possible	O
to	O
cut	O
off	O
one	O
's	O
access	O
to	O
still-unexplored	O
parts	O
of	O
a	O
maze	B-Application
if	O
,	O
instead	O
of	O
turning	O
back	O
,	O
we	O
arbitrarily	O
pick	O
another	O
entrance	O
.	O
</s>
<s>
Essentially	O
,	O
this	O
algorithm	O
,	O
which	O
was	O
discovered	O
in	O
the	O
19th	O
century	O
,	O
has	O
been	O
used	O
about	O
a	O
hundred	O
years	O
later	O
as	O
depth-first	B-Algorithm
search	I-Algorithm
.	O
</s>
<s>
Dead-end	O
filling	O
is	O
an	O
algorithm	O
for	O
solving	O
mazes	B-Application
that	O
fills	O
all	O
dead	O
ends	O
,	O
leaving	O
only	O
the	O
correct	O
ways	O
unfilled	O
.	O
</s>
<s>
It	O
can	O
be	O
used	O
for	O
solving	O
mazes	B-Application
on	O
paper	O
or	O
with	O
a	O
computer	O
program	O
,	O
but	O
it	O
is	O
not	O
useful	O
to	O
a	O
person	O
inside	O
an	O
unknown	O
maze	B-Application
since	O
this	O
method	O
looks	O
at	O
the	O
entire	O
maze	B-Application
at	O
once	O
.	O
</s>
<s>
Dead-end	O
filling	O
cannot	O
accidentally	O
"	O
cut	O
off	O
"	O
the	O
start	O
from	O
the	O
finish	O
since	O
each	O
step	O
of	O
the	O
process	O
preserves	O
the	O
topology	O
of	O
the	O
maze	B-Application
.	O
</s>
<s>
Thus	O
if	O
dead-end	O
filling	O
is	O
done	O
on	O
a	O
perfect	O
maze	B-Application
(	O
maze	B-Application
with	O
no	O
loops	O
)	O
,	O
then	O
only	O
the	O
solution	O
will	O
remain	O
.	O
</s>
<s>
If	O
it	O
is	O
done	O
on	O
a	O
partially	O
braid	O
maze	B-Application
(	O
maze	B-Application
with	O
some	O
loops	O
)	O
,	O
then	O
every	O
possible	O
solution	O
will	O
remain	O
but	O
nothing	O
more	O
.	O
</s>
<s>
If	O
given	O
an	O
omniscient	O
view	O
of	O
the	O
maze	B-Application
,	O
a	O
simple	O
recursive	O
algorithm	O
can	O
tell	O
one	O
how	O
to	O
get	O
to	O
the	O
end	O
.	O
</s>
<s>
This	O
is	O
in	O
effect	O
a	O
depth-first	B-Algorithm
search	I-Algorithm
expressed	O
in	O
term	O
of	O
grid	O
points	O
.	O
</s>
<s>
Here	O
is	O
a	O
sample	O
code	O
in	O
Java	B-Language
:	O
</s>
<s>
The	O
maze-routing	O
algorithm	O
is	O
a	O
low	O
overhead	O
method	O
to	O
find	O
the	O
way	O
between	O
any	O
two	O
locations	O
of	O
the	O
maze	B-Application
.	O
</s>
<s>
The	O
algorithm	O
is	O
initially	O
proposed	O
for	O
chip	B-Architecture
multiprocessors	I-Architecture
(	O
CMPs	O
)	O
domain	O
and	O
guarantees	O
to	O
work	O
for	O
any	O
grid-based	O
maze	B-Application
.	O
</s>
<s>
In	O
addition	O
to	O
finding	O
paths	O
between	O
two	O
locations	O
of	O
the	O
grid	O
(	O
maze	B-Application
)	O
,	O
the	O
algorithm	O
can	O
detect	O
when	O
there	O
is	O
no	O
path	O
between	O
the	O
source	O
and	O
destination	O
.	O
</s>
<s>
Also	O
,	O
the	O
algorithm	O
is	O
to	O
be	O
used	O
by	O
an	O
inside	O
traveler	O
with	O
no	O
prior	O
knowledge	O
of	O
the	O
maze	B-Application
with	O
fixed	O
memory	O
complexity	O
regardless	O
of	O
the	O
maze	B-Application
size	O
;	O
requiring	O
4	O
variables	O
in	O
total	O
for	O
finding	O
the	O
path	O
and	O
detecting	O
the	O
unreachable	O
locations	O
.	O
</s>
<s>
Maze-routing	O
algorithm	O
uses	O
the	O
notion	O
of	O
Manhattan	O
distance	O
(	O
MD	O
)	O
and	O
relies	O
on	O
the	O
property	O
of	O
grids	O
that	O
the	O
MD	O
increments/decrements	O
exactly	O
by	O
1	O
when	O
moving	O
from	O
one	O
location	O
to	O
any	O
4	O
neighboring	O
locations	O
.	O
</s>
<s>
When	O
a	O
maze	B-Application
has	O
multiple	O
solutions	O
,	O
the	O
solver	O
may	O
want	O
to	O
find	O
the	O
shortest	O
path	O
from	O
start	O
to	O
finish	O
.	O
</s>
<s>
One	O
such	O
algorithm	O
finds	O
the	O
shortest	O
path	O
by	O
implementing	O
a	O
breadth-first	B-Algorithm
search	I-Algorithm
,	O
while	O
another	O
,	O
the	O
A*	B-Protocol
algorithm	I-Protocol
,	O
uses	O
a	O
heuristic	B-Algorithm
technique	O
.	O
</s>
<s>
The	O
breadth-first	B-Algorithm
search	I-Algorithm
algorithm	O
uses	O
a	O
queue	B-Application
to	O
visit	O
cells	O
in	O
increasing	O
distance	O
order	O
from	O
the	O
start	O
until	O
the	O
finish	O
is	O
reached	O
.	O
</s>
<s>
Each	O
visited	O
cell	O
needs	O
to	O
keep	O
track	O
of	O
its	O
distance	O
from	O
the	O
start	O
or	O
which	O
adjacent	O
cell	O
nearer	O
to	O
the	O
start	O
caused	O
it	O
to	O
be	O
added	O
to	O
the	O
queue	B-Application
.	O
</s>
<s>
The	O
breadth-first	B-Algorithm
search	I-Algorithm
in	O
its	O
simplest	O
form	O
has	O
its	O
limitations	O
,	O
like	O
finding	O
the	O
shortest	O
path	O
in	O
weighted	O
graphs	O
.	O
</s>
