ArticleslgStudy

computer science

Tompkins–Paige algorithm

Tompkins–Paige 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 Tompkins–Paige algorithm rather than just read about it. In short: The Tompkins–Paige algorithm is a computer algorithm for generating all permutations of a finite set of objects. The method Let P and c be arrays of length n with 1-based indexing (i.e. the first entry of an array has index 1).

Key takeaways

  • Tompkins–Paige 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 Tompkins–Paige algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Tompkins–Paige algorithm from memory before moving on to harder problems.

Reference excerpt

The Tompkins–Paige algorithm is a computer algorithm for generating all permutations of a finite set of objects.

The method Let P and c be arrays of length n with 1-based indexing (i.e. the first entry of an array has index 1). The algorithm for generating all n! permutations of the set {1, 2, ..., n} is given by the following pseudocode:

P ← [1, 2, ..., n]; yield P; c ← [*, 1, ..., 1]; (the first entry of c is not used) i ← 2; while i ≤ n do left-rotate the first i entries of P; (e.g. left-rotating the first 4 entries of [4, 2, 5, 3, 1] would give [2, 5, 3, 4, 1]) if c[i] < i then c[i] ← c[i] + 1; i ← 2; yield P; else c[i] ← 1; i ← i+1;

In the above pseudocode, the statement "yield P" means to output or record the set of permuted indices P. If the algorithm is implemented correctly, P will be yielded exactly n! times, each with a different set of permuted indices. This algorithm is not the most efficient one among all existing permutation generation methods. Not only does it have to keep track of an auxiliary counting array (c), redundant permutations are also produced and ignored (because P is not yielded after left-rotation if c[i] ≥ i) in the course of generation. For instance, when n = 4, the algorithm will first yield P = [1,2,3,4] and then generate the other 23 permutations in 40 iterations (i.e. in 17 iterations, there are redundant permutations and P is not yielded). The following lists, in the order of generation, all 41 values of P, where the parenthesized ones are redundant:

P = 1234 c = *111 i=2 P = 2134 c = *211 i=2 P = (1234) c = *111 i=3 P = 2314 c = *121 i=2 P = 3214 c = *221 i=2 P = (2314) c = *121 i=3 P = 3124 c = *131 i=2 P = 1324 c = *231 i=2 P = (3124) c = *131 i=3 P = (1234) c = *111 i=4 P = 2341 c = *112 i=2 P = 3241 c = *212 i=2 P = (2341) c = *112 i=3 P = 3421 c = *122 i=2 P = 4321 c = *222 i=2 P = (3421) c = *122 i=3 P = 4231 c = *132 i=2 P = 2431 c = *232 i=2 P = (4231) c = *132 i=3 P = (2341) c = *112 i=4 P = 3412 c = *113 i=2 P = 4312 c = *213 i=2 P = (3412) c = *113 i=3 P = 4132 c = *123 i=2 P = 1432 c = *223 i=2 P = (4132) c = *123 i=3 P = 1342 c = *133 i=2 P = 3142 c = *233 i=2 P = (1342) c = *133 i=3 P = (3412) c = *113 i=4 P = 4123 c = *114 i=2 P = 1423 c = *214 i=2 P = (4123) c = *114 i=3 P = 1243 c = *124 i=2 P = 2143 c = *224 i=2 P = (1243) c = *124 i=3 P = 2413 c = *134 i=2 P = 4213 c = *234 i=2 P = (2413) c = *134 i=3 P = (4123) c = *114 i=4 P = (1234) c = *111 i=5

References

Worked examples

Example 1 — a first encounter with Tompkins–Paige algorithm

Start with the simplest possible case. Write down what Tompkins–Paige 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 Tompkins–Paige 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 Tompkins–Paige 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 Tompkins–Paige algorithm

In research
Tompkins–Paige 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 Tompkins–Paige 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
Tompkins–Paige algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Combinatorial algorithms, Permutations, so understanding it makes those chapters shorter.
In everyday life
Look for Tompkins–Paige 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 “Tompkins–Paige algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Tompkins–Paige algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Tompkins–Paige 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 Tompkins–Paige algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Tompkins–Paige algorithm in simple terms?

The Tompkins–Paige algorithm is a computer algorithm for generating all permutations of a finite set of objects. The method Let P and c be arrays of length n with 1-based indexing (i.e. the first entry of an array has index 1).

Why does Tompkins–Paige 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 Tompkins–Paige 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 Tompkins–Paige algorithm.

Tags

  • Combinatorial algorithms
  • Permutations

Keep exploring