Pollard's rho algorithm is an
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
for
integer factorization
In mathematics, integer factorization is the decomposition of a positive integer into a product of integers. Every positive integer greater than 1 is either the product of two or more integer factors greater than 1, in which case it is a comp ...
. It was invented by
John Pollard in 1975. It uses only a small amount of space, and its expected running time is proportional to the
square root
In mathematics, a square root of a number is a number such that y^2 = x; in other words, a number whose ''square'' (the result of multiplying the number by itself, or y \cdot y) is . For example, 4 and −4 are square roots of 16 because 4 ...
of the smallest
prime factor
A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
of the
composite number
A composite number is a positive integer that can be formed by multiplying two smaller positive integers. Accordingly it is a positive integer that has at least one divisor other than 1 and itself. Every positive integer is composite, prime numb ...
being factorized.
Core ideas
The algorithm is used to factorize a number
, where
is a non-trivial factor. A
polynomial
In mathematics, a polynomial is a Expression (mathematics), mathematical expression consisting of indeterminate (variable), indeterminates (also called variable (mathematics), variables) and coefficients, that involves only the operations of addit ...
modulo
, called
(e.g.,
), is used to generate a
pseudorandom sequence. It is important to note that
must be a polynomial. A starting value, say 2, is chosen, and the sequence continues as
,
,
, etc. The sequence is related to another sequence
. Since
is not known beforehand, this sequence cannot be explicitly computed in the algorithm. Yet in it lies the core idea of the algorithm.
Because the number of possible values for these sequences is finite, both the
sequence, which is mod
, and
sequence will eventually repeat, even though these values are unknown. If the sequences were to behave like random numbers, the
birthday paradox
In probability theory, the birthday problem asks for the probability that, in a set of randomly chosen people, at least two will share the same birthday. The birthday paradox is the counterintuitive fact that only 23 people are needed for that ...
implies that the number of
before a repetition occurs would be expected to be
, where
is the number of possible values. So the sequence
will likely repeat much earlier than the sequence
. When one has found a
such that
but
, the number
is a multiple of
, so a non-trivial divisor has been found.
Once a sequence has a repeated value, the sequence will cycle, because each value depends only on the one before it. This structure of eventual cycling gives rise to the name "rho algorithm", owing to similarity to the shape of the Greek letter ''ρ'' when the values
,
, etc. are represented as nodes in a
directed graph.

This is detected by
Floyd's cycle-finding algorithm: two nodes
and
(i.e.,
and
) are kept. In each step, one moves to the next node in the sequence and the other moves forward by two nodes. After that, it is checked whether
. If it is not 1, then this implies that there is a repetition in the
sequence (i.e.
. This works because if the
is the same as
, the difference between
and
is necessarily a multiple of
. Although this always happens eventually, the resulting
greatest common divisor
In mathematics, the greatest common divisor (GCD), also known as greatest common factor (GCF), of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers. For two integers , , the greatest co ...
(GCD) is a divisor of
other than 1. This may be
itself, since the two sequences might repeat at the same time. In this (uncommon) case the algorithm fails, it can be repeated with a different parameter.
Algorithm
The algorithm takes as its inputs , the
integer
An integer is the number zero (0), a positive natural number (1, 2, 3, ...), or the negation of a positive natural number (−1, −2, −3, ...). The negations or additive inverses of the positive natural numbers are referred to as negative in ...
to be factored; and , a polynomial in computed modulo . In the original algorithm,
, but nowadays it is more common to use
. The output is either a non-trivial factor of , or failure.
It performs the following steps:
[ (this section discusses only Pollard's rho algorithm).]
Pseudocode for Pollard's rho algorithm
x ← 2 // starting value
y ← x
d ← 1
while d = 1:
x ← g(x)
y ← g(g(y))
d ← gcd(, x - y, , n)
if d = n:
return failure
else:
return d
Here and corresponds to and in the previous section. Note that this algorithm may fail to find a nontrivial factor even when is composite. In that case, the method can be tried again, using a starting value of ''x'' other than 2 (
) or a different ,
, with
.
Example factorization
Let
and
.

Now 97 is a non-trivial factor of 8051. Starting values other than may give the cofactor (83) instead of 97. One extra iteration is shown above to make it clear that moves twice as fast as . Note that even after a repetition, the GCD can return to 1.
Variants
In 1980,
Richard Brent published a faster variant of the rho algorithm. He used the same core ideas as Pollard but a different method of cycle detection, replacing
Floyd's cycle-finding algorithm with the related
Brent's cycle finding method. CLRS gives a heuristic analysis and failure conditions (the trivial divisor
is found).
A further improvement was made by Pollard and Brent. They observed that if
, then also
for any positive integer . In particular, instead of computing
at every step, it suffices to define as the product of 100 consecutive
terms modulo , and then compute a single
. A major speed up results as 100 steps are replaced with 99 multiplications modulo and a single . Occasionally it may cause the algorithm to fail by introducing a repeated factor, for instance when is a
square
In geometry, a square is a regular polygon, regular quadrilateral. It has four straight sides of equal length and four equal angles. Squares are special cases of rectangles, which have four equal angles, and of rhombuses, which have four equal si ...
. But it then suffices to go back to the previous term, where
, and use the regular ''ρ'' algorithm from there.
[Exercise 31.9-4 in CLRS]
Application
The algorithm is very fast for numbers with small factors, but slower in cases where all factors are large. The ''ρ'' algorithm's most remarkable success was the 1980 factorization of the
Fermat number
In mathematics, a Fermat number, named after Pierre de Fermat (1601–1665), the first known to have studied them, is a natural number, positive integer of the form:F_ = 2^ + 1, where ''n'' is a non-negative integer. The first few Fermat numbers ...
= 1238926361552897 × 93461639715357977769163558199606896584051237541638188580280321.
The ''ρ'' algorithm was a good choice for because the prime factor = 1238926361552897 is much smaller than the other factor. The factorization took 2 hours on a
UNIVAC
UNIVAC (Universal Automatic Computer) was a line of electronic digital stored-program computers starting with the products of the Eckert–Mauchly Computer Corporation. Later the name was applied to a division of the Remington Rand company and ...
1100/42.
Example: factoring = 10403 = 101 · 103
The following table shows numbers produced by the algorithm, starting with
and using the polynomial
.
The third and fourth columns of the table contain additional information not known by the algorithm.
They are included to show how the algorithm works.
The first repetition modulo 101 is 97 which occurs in step 17. The repetition is not detected until step 23, when
. This causes
to be
, and a factor is found.
Complexity
If the pseudorandom number
occurring in the Pollard ''ρ'' algorithm were an actual random number, it would follow that success would be achieved half the time, by the
birthday paradox
In probability theory, the birthday problem asks for the probability that, in a set of randomly chosen people, at least two will share the same birthday. The birthday paradox is the counterintuitive fact that only 23 people are needed for that ...
in
iterations. It is believed that the same analysis applies as well to the actual rho algorithm, but this is a heuristic claim, and rigorous analysis of the algorithm remains open.
[.]
See also
*
Pollard's rho algorithm for logarithms
*
Pollard's kangaroo algorithm
Notes
References
Further reading
* Describes the improvements available from different iteration functions and cycle-finding algorithms.
*
*
External links
Comprehensive article on Pollard's Rho algorithm aimed at an introductory-level audience*
{{DEFAULTSORT:Pollard's Rho Algorithm
Integer factorization algorithms