ArticleslgStudy

computer science

Pollard's rho algorithm

Pollard's rho algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pollard's rho algorithm rather than just read about it. In short: Pollard's rho algorithm is an algorithm for integer factorization. It was invented by John Pollard in 1975.

Pollard's rho algorithm — main illustration
Pollard's rho algorithm — illustration

Key takeaways

  • Pollard's rho algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pollard's rho algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pollard's rho algorithm from memory before moving on to harder problems.

Reference excerpt

Pollard's rho algorithm is an algorithm for integer factorization. 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 of the smallest prime factor of the composite number being factorized.

Core ideas The algorithm is used to factorize a number n=pq, where p is a non-trivial factor. A polynomial modulo n, called g(x) (e.g., g(x)=(x2+1)modn), is used to generate a pseudorandom sequence. g(x) must be a polynomial. A starting value, say 2, is chosen, and the sequence continues as x1=g(2), x2=g(g(2)), x3=g(g(g(2))), etc. The sequence is related to another sequence {xkmodp}. Since p 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 {xk} sequence, which is mod n, and {xkmodp} sequence will eventually repeat, even though these values are unknown. If the sequences were to behave like random numbers, the birthday paradox implies that the number of xk before a repetition occurs would be expected to be O(N), where N is the number of possible values. So the sequence {xkmodp} will likely repeat much earlier than the sequence {xk}. When one has found a k1,k2 such that xk1≠xk2 but xk1≡xk2modp, the number |xk1−xk2| is a multiple of p, 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 x1modp, x2modp, etc. are represented as nodes in a directed graph.

This is detected by Floyd's cycle-finding algorithm: two nodes i and j (i.e., xi and xj) 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 gcd⁡(xi−xj,n)≠1. If it is not 1, then this implies that there is a repetition in the {xkmodp} sequence (i.e. ximodp=xjmodp). This works because if the ximodp is the same as xjmodp, the difference between xi and xj is necessarily a multiple of p. Although this always happens eventually, the resulting greatest common divisor (GCD) is a divisor of n other than 1. This may be n itself (if ⁠ximodn⁠ equals ⁠xjmodn⁠) since the two sequences might repeat at the same time. In this (uncommon) case that the algorithm fails, it can be repeated with a different starting parameter ⁠x0⁠.

Algorithm The algorithm takes as its inputs n, the integer to be factored; and ⁠g(x)⁠, a polynomial in x computed modulo n. In the original algorithm, g(x)=(x2−1)modn, but nowadays it is more common to use g(x)=(x2+1)modn. The output is either a non-trivial factor of n, or failure. It performs the following steps: 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 x and y corresponds to ⁠xi⁠ and ⁠xj⁠ in the previous section. Note that this algorithm may fail to find a nontrivial factor even when n is composite. In that case, the method can be tried again, using a starting value of x other than 2 (0≤x<n) or a different ⁠g(x)⁠, such as g(x)=(x2+b)modn, with 1≤b<n.

Example factorization Let n=8051 and ⁠g(x)=(x2+1)mod8051⁠.

Now 97 is a non-trivial factor of 8051. Starting values other than x = y = 2 may give the cofactor (83) instead of 97. One extra iteration is shown above to make it clear that y moves twice as fast as x. 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 (Cormen et Al. Introduction to Algorithms book) gives a heuristic analysis and failure conditions (the trivial divisor n is found). A further improvement was made by Pollard and Brent. They observed that if gcd⁡(a,n)>1, then also gcd⁡(ab,n)>1 for any positive integer ⁠b⁠. In particular, instead of computing gcd⁡(|x−y|,n) at every step, it suffices to define ⁠z⁠ as the product of 100 consecutive |x−y| terms modulo ⁠n⁠, and then compute a single gcd⁡(z,n). A major speed up results as 100 gcd steps are replaced with 99 multiplications modulo ⁠n⁠ and a single gcd. Occasionally it may cause the algorithm to fail by introducing a repeated factor, for instance when ⁠n⁠ is a square. But it then suffices to go back to the previous gcd term, where gcd⁡(z,n)=1, and use the regular ρ algorithm from there.

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 F8 = 1238926361552897 × 93461639715357977769163558199606896584051237541638188580280321. The ρ algorithm was a good choice for F8 because the prime factor p = 1238926361552897 is much smaller than the other factor. The factorization took 2 hours on a UNIVAC 1100/42.

Example: factoring n = 10403 = 101 · 103 The following table shows numbers produced by the algorithm, starting with x=2 and using the polynomial g(x)=(x2+1)mod10403. 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 x≡y(mod101). This causes gcd⁡(x−y,n)=gcd⁡(2799−9970,n) to be p=101, and a factor is found.

Complexity If the pseudorandom number x=g(x) 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 O(p)≤O(n1/4) 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

… excerpt ends here. Continue reading the full article.

Illustrations

Pollard's rho algorithm: Pollard's rho algorithm example factorization for n=253 and ⁠g(x)=x2mod253⁠, with starting value 2. The example is using Floyd's cycle-finding algorithm.
Pollard's rho algorithm example factorization for n=253 and ⁠g(x)=x2mod253⁠, with starting value 2. The example is using Floyd's cycle-finding algorithm.

Worked examples

Example 1 — a first encounter with Pollard's rho algorithm

Start with the simplest possible case. Write down what Pollard's rho algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pollard's rho algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pollard's rho algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pollard's rho algorithm

In research
Pollard's rho algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pollard's rho algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pollard's rho algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Integer factorization algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Pollard's rho algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Pollard's rho algorithm” →

How to study Pollard's rho algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pollard's rho algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pollard's rho algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pollard's rho algorithm in simple terms?

Pollard's rho algorithm is an algorithm for integer factorization. It was invented by John Pollard in 1975.

Why does Pollard's rho algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pollard's rho algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pollard's rho algorithm.

Tags

  • Integer factorization algorithms

Keep exploring