<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
cycle	B-Algorithm
detection	I-Algorithm
or	O
cycle	O
finding	O
is	O
the	O
algorithmic	O
problem	O
of	O
finding	O
a	O
cycle	O
in	O
a	O
sequence	O
of	O
iterated	B-Algorithm
function	I-Algorithm
values	O
.	O
</s>
<s>
Cycle	B-Algorithm
detection	I-Algorithm
is	O
the	O
problem	O
of	O
finding	O
and	O
,	O
given	O
and	O
.	O
</s>
<s>
Alternatively	O
,	O
Brent	O
's	O
algorithm	O
is	O
based	O
on	O
the	O
idea	O
of	O
exponential	B-Algorithm
search	I-Algorithm
.	O
</s>
<s>
The	O
applications	O
of	O
cycle	B-Algorithm
detection	I-Algorithm
include	O
testing	O
the	O
quality	O
of	O
pseudorandom	B-Algorithm
number	I-Algorithm
generators	I-Algorithm
and	O
cryptographic	B-Algorithm
hash	I-Algorithm
functions	I-Algorithm
,	O
computational	O
number	O
theory	O
algorithms	O
,	O
detection	O
of	O
infinite	B-Algorithm
loops	I-Algorithm
in	O
computer	B-Application
programs	I-Application
and	O
periodic	O
configurations	O
in	O
cellular	O
automata	O
,	O
automated	O
shape	B-Language
analysis	I-Language
of	O
linked	B-Data_Structure
list	I-Data_Structure
data	B-General_Concept
structures	I-General_Concept
,	O
and	O
detection	O
of	O
deadlocks	B-Operating_System
for	O
transactions	B-General_Concept
management	I-General_Concept
in	O
DBMS	O
.	O
</s>
<s>
The	O
cycle	B-Algorithm
detection	I-Algorithm
problem	O
is	O
the	O
task	O
of	O
finding	O
and	O
.	O
</s>
<s>
Rather	O
,	O
a	O
cycle	B-Algorithm
detection	I-Algorithm
algorithm	O
may	O
be	O
given	O
access	O
either	O
to	O
the	O
sequence	O
of	O
values	O
,	O
or	O
to	O
a	O
subroutine	O
for	O
calculating	O
.	O
</s>
<s>
Typically	O
,	O
also	O
,	O
the	O
space	O
complexity	O
of	O
an	O
algorithm	O
for	O
the	O
cycle	B-Algorithm
detection	I-Algorithm
problem	O
is	O
of	O
importance	O
:	O
we	O
wish	O
to	O
solve	O
the	O
problem	O
while	O
using	O
an	O
amount	O
of	O
memory	O
significantly	O
smaller	O
than	O
it	O
would	O
take	O
to	O
store	O
the	O
entire	O
sequence	O
.	O
</s>
<s>
In	O
some	O
applications	O
,	O
and	O
in	O
particular	O
in	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
for	O
integer	O
factorization	O
,	O
the	O
algorithm	O
has	O
much	O
more	O
limited	O
access	O
to	O
and	O
to	O
.	O
</s>
<s>
In	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
,	O
for	O
instance	O
,	O
is	O
the	O
set	O
of	O
integers	O
modulo	O
an	O
unknown	O
prime	O
factor	O
of	O
the	O
number	O
to	O
be	O
factorized	O
,	O
so	O
even	O
the	O
size	O
of	O
is	O
unknown	O
to	O
the	O
algorithm	O
.	O
</s>
<s>
To	O
allow	O
cycle	B-Algorithm
detection	I-Algorithm
algorithms	O
to	O
be	O
used	O
with	O
such	O
limited	O
knowledge	O
,	O
they	O
may	O
be	O
designed	O
based	O
on	O
the	O
following	O
capabilities	O
.	O
</s>
<s>
The	O
equality	O
test	O
action	O
may	O
involve	O
some	O
nontrivial	O
computation	O
:	O
for	O
instance	O
,	O
in	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
,	O
it	O
is	O
implemented	O
by	O
testing	O
whether	O
the	O
difference	O
between	O
two	O
stored	O
values	O
has	O
a	O
nontrivial	O
greatest	O
common	O
divisor	O
with	O
the	O
number	O
to	O
be	O
factored	O
.	O
</s>
<s>
In	O
this	O
context	O
,	O
by	O
analogy	O
to	O
the	O
pointer	B-Application
machine	I-Application
model	O
of	O
computation	O
,	O
an	O
algorithm	O
that	O
only	O
uses	O
pointer	O
copying	O
,	O
advancement	O
within	O
the	O
sequence	O
,	O
and	O
equality	O
tests	O
may	O
be	O
called	O
a	O
pointer	B-Application
algorithm	I-Application
.	O
</s>
<s>
If	O
the	O
input	O
is	O
given	O
as	O
a	O
subroutine	O
for	O
calculating	O
,	O
the	O
cycle	B-Algorithm
detection	I-Algorithm
problem	O
may	O
be	O
trivially	O
solved	O
using	O
only	O
function	O
applications	O
,	O
simply	O
by	O
computing	O
the	O
sequence	O
of	O
values	O
and	O
using	O
a	O
data	B-General_Concept
structure	I-General_Concept
such	O
as	O
a	O
hash	B-Algorithm
table	I-Algorithm
to	O
store	O
these	O
values	O
and	O
test	O
whether	O
each	O
subsequent	O
value	O
has	O
already	O
been	O
stored	O
.	O
</s>
<s>
Additionally	O
,	O
to	O
implement	O
this	O
method	O
as	O
a	O
pointer	B-Application
algorithm	I-Application
would	O
require	O
applying	O
the	O
equality	O
test	O
to	O
each	O
pair	O
of	O
values	O
,	O
resulting	O
in	O
quadratic	O
time	O
overall	O
.	O
</s>
<s>
Thus	O
,	O
research	O
in	O
this	O
area	O
has	O
concentrated	O
on	O
two	O
goals	O
:	O
using	O
less	O
space	O
than	O
this	O
naive	O
algorithm	O
,	O
and	O
finding	O
pointer	B-Application
algorithms	I-Application
that	O
use	O
fewer	O
equality	O
tests	O
.	O
</s>
<s>
Floyd	O
's	O
cycle-finding	O
algorithm	O
is	O
a	O
pointer	B-Application
algorithm	I-Application
that	O
uses	O
only	O
two	O
pointers	O
,	O
which	O
move	O
through	O
the	O
sequence	O
at	O
different	O
speeds	O
.	O
</s>
<s>
The	O
following	O
Python	B-Language
code	I-Language
shows	O
how	O
this	O
idea	O
may	O
be	O
implemented	O
as	O
an	O
algorithm	O
.	O
</s>
<s>
This	O
code	O
only	O
accesses	O
the	O
sequence	O
by	O
storing	O
and	O
copying	O
pointers	O
,	O
function	O
evaluations	O
,	O
and	O
equality	O
tests	O
;	O
therefore	O
,	O
it	O
qualifies	O
as	O
a	O
pointer	B-Application
algorithm	I-Application
.	O
</s>
<s>
Richard	O
P	O
.	O
Brent	O
described	O
an	O
alternative	O
cycle	B-Algorithm
detection	I-Algorithm
algorithm	O
that	O
,	O
like	O
the	O
tortoise	O
and	O
hare	O
algorithm	O
,	O
requires	O
only	O
two	O
pointers	O
into	O
the	O
sequence	O
.	O
</s>
<s>
The	O
following	O
Python	B-Language
code	I-Language
shows	O
how	O
this	O
technique	O
works	O
in	O
more	O
detail	O
.	O
</s>
<s>
Like	O
the	O
tortoise	O
and	O
hare	O
algorithm	O
,	O
this	O
is	O
a	O
pointer	B-Application
algorithm	I-Application
that	O
uses	O
tests	O
and	O
function	O
evaluations	O
and	O
storage	O
space	O
.	O
</s>
<s>
Brent	O
claims	O
that	O
,	O
on	O
average	O
,	O
his	O
cycle	O
finding	O
algorithm	O
runs	O
around	O
36%	O
more	O
quickly	O
than	O
Floyd	O
's	O
and	O
that	O
it	O
speeds	O
up	O
the	O
Pollard	B-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
by	O
around	O
24%	O
.	O
</s>
<s>
Although	O
his	O
main	O
intended	O
application	O
was	O
in	O
integer	O
factorization	O
algorithms	O
,	O
Brent	O
also	O
discusses	O
applications	O
in	O
testing	O
pseudorandom	B-Algorithm
number	I-Algorithm
generators	I-Algorithm
.	O
</s>
<s>
A	O
number	O
of	O
authors	O
have	O
studied	O
techniques	O
for	O
cycle	B-Algorithm
detection	I-Algorithm
that	O
use	O
more	O
memory	O
than	O
Floyd	O
's	O
and	O
Brent	O
's	O
methods	O
,	O
but	O
detect	O
cycles	O
more	O
quickly	O
.	O
</s>
<s>
In	O
order	O
to	O
do	O
so	O
quickly	O
,	O
they	O
typically	O
use	O
a	O
hash	B-Algorithm
table	I-Algorithm
or	O
similar	O
data	B-General_Concept
structure	I-General_Concept
for	O
storing	O
the	O
previously-computed	O
values	O
,	O
and	O
therefore	O
are	O
not	O
pointer	B-Application
algorithms	I-Application
:	O
in	O
particular	O
,	O
they	O
usually	O
cannot	O
be	O
applied	O
to	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
By	O
choosing	O
to	O
be	O
a	O
number	O
close	O
to	O
one	O
,	O
and	O
storing	O
the	O
sequence	O
values	O
at	O
indices	O
that	O
are	O
near	O
a	O
sequence	O
of	O
consecutive	O
powers	O
of	O
,	O
a	O
cycle	B-Algorithm
detection	I-Algorithm
algorithm	O
can	O
use	O
a	O
number	O
of	O
function	O
evaluations	O
that	O
is	O
within	O
an	O
arbitrarily	O
small	O
factor	O
of	O
the	O
optimum	O
.	O
</s>
<s>
As	O
Nivasch	O
shows	O
,	O
the	O
items	O
with	O
this	O
technique	O
can	O
be	O
maintained	O
using	O
a	O
stack	B-Application
data	I-Application
structure	I-Application
,	O
and	O
each	O
successive	O
sequence	O
value	O
need	O
be	O
compared	O
only	O
to	O
the	O
top	O
of	O
the	O
stack	B-Application
.	O
</s>
<s>
Running	O
the	O
same	O
algorithm	O
with	O
multiple	O
stacks	B-Application
,	O
using	O
random	O
permutations	O
of	O
the	O
values	O
to	O
reorder	O
the	O
values	O
within	O
each	O
stack	B-Application
,	O
allows	O
a	O
time	O
–	O
space	O
tradeoff	O
similar	O
to	O
the	O
previous	O
algorithms	O
.	O
</s>
<s>
However	O
,	O
even	O
the	O
version	O
of	O
this	O
algorithm	O
with	O
a	O
single	O
stack	B-Application
is	O
not	O
a	O
pointer	B-Application
algorithm	I-Application
,	O
due	O
to	O
the	O
comparisons	O
needed	O
to	O
determine	O
which	O
of	O
two	O
values	O
is	O
smaller	O
.	O
</s>
<s>
Any	O
cycle	B-Algorithm
detection	I-Algorithm
algorithm	O
that	O
stores	O
at	O
most	O
values	O
from	O
the	O
input	O
sequence	O
must	O
perform	O
at	O
least	O
function	O
evaluations	O
.	O
</s>
<s>
Cycle	B-Algorithm
detection	I-Algorithm
has	O
been	O
used	O
in	O
many	O
applications	O
.	O
</s>
<s>
Determining	O
the	O
cycle	O
length	O
of	O
a	O
pseudorandom	B-Algorithm
number	I-Algorithm
generator	I-Algorithm
is	O
one	O
measure	O
of	O
its	O
strength	O
.	O
</s>
<s>
Brent	O
describes	O
the	O
results	O
of	O
testing	O
a	O
linear	B-Algorithm
congruential	I-Algorithm
generator	I-Algorithm
in	O
this	O
fashion	O
;	O
its	O
period	O
turned	O
out	O
to	O
be	O
significantly	O
smaller	O
than	O
advertised	O
.	O
</s>
<s>
Several	O
number-theoretic	O
algorithms	O
are	O
based	O
on	O
cycle	B-Algorithm
detection	I-Algorithm
,	O
including	O
Pollard	B-Algorithm
's	I-Algorithm
rho	I-Algorithm
algorithm	I-Algorithm
for	O
integer	O
factorization	O
and	O
his	O
related	O
kangaroo	O
algorithm	O
for	O
the	O
discrete	O
logarithm	O
problem	O
.	O
</s>
<s>
For	O
instance	O
,	O
Quisquater	O
and	O
Delescaille	O
apply	O
cycle	B-Algorithm
detection	I-Algorithm
algorithms	O
in	O
the	O
search	O
for	O
a	O
message	O
and	O
a	O
pair	O
of	O
Data	B-Algorithm
Encryption	I-Algorithm
Standard	I-Algorithm
keys	O
that	O
map	O
that	O
message	O
to	O
the	O
same	O
encrypted	O
value	O
;	O
Kaliski	O
,	O
Rivest	O
,	O
and	O
Sherman	O
also	O
use	O
cycle	B-Algorithm
detection	I-Algorithm
algorithms	O
to	O
attack	O
DES	B-Algorithm
.	O
</s>
<s>
The	O
technique	O
may	O
also	O
be	O
used	O
to	O
find	O
a	O
collision	B-Algorithm
in	O
a	O
cryptographic	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
.	O
</s>
<s>
Cycle	B-Algorithm
detection	I-Algorithm
may	O
be	O
helpful	O
as	O
a	O
way	O
of	O
discovering	O
infinite	B-Algorithm
loops	I-Algorithm
in	O
certain	O
types	O
of	O
computer	B-Application
programs	I-Application
.	O
</s>
<s>
Periodic	O
configurations	O
in	O
cellular	O
automaton	O
simulations	O
may	O
be	O
found	O
by	O
applying	O
cycle	B-Algorithm
detection	I-Algorithm
algorithms	O
to	O
the	O
sequence	O
of	O
automaton	O
states	O
.	O
</s>
<s>
Shape	B-Language
analysis	I-Language
of	O
linked	B-Data_Structure
list	I-Data_Structure
data	B-General_Concept
structures	I-General_Concept
is	O
a	O
technique	O
for	O
verifying	O
the	O
correctness	O
of	O
an	O
algorithm	O
using	O
those	O
structures	O
.	O
</s>
<s>
In	O
Common	B-Language
Lisp	I-Language
,	O
the	O
S-expression	B-Protocol
printer	O
,	O
under	O
control	O
of	O
the	O
*	O
print-circle*	O
variable	O
,	O
detects	O
circular	O
list	O
structure	O
and	O
prints	O
it	O
compactly	O
.	O
</s>
<s>
briefly	O
mentions	O
an	O
application	O
to	O
computer	B-Application
simulation	I-Application
of	O
celestial	O
mechanics	O
,	O
which	O
she	O
attributes	O
to	O
William	O
Kahan	O
.	O
</s>
<s>
In	O
this	O
application	O
,	O
cycle	B-Algorithm
detection	I-Algorithm
in	O
the	O
phase	O
space	O
of	O
an	O
orbital	O
system	O
may	O
be	O
used	O
to	O
determine	O
whether	O
the	O
system	O
is	O
periodic	O
to	O
within	O
the	O
accuracy	O
of	O
the	O
simulation	O
.	O
</s>
<s>
In	O
Mandelbrot	B-Algorithm
Set	I-Algorithm
fractal	O
generation	O
some	O
performance	O
techniques	O
are	O
used	O
to	O
speed	O
up	O
the	O
image	O
generation	O
.	O
</s>
<s>
Some	O
cycle	B-Algorithm
detection	I-Algorithm
algorithms	O
have	O
to	O
be	O
implemented	O
in	O
order	O
to	O
implement	O
this	O
technique	O
.	O
</s>
