ArticleslgStudy

computer science

God's algorithm

God's 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 God's algorithm rather than just read about it. In short: God's algorithm of the Rubik cube is a notion originating in discussions of ways to solve the Rubik's Cube puzzle, but which can also be applied to other combinatorial puzzles and mathematical games. It refers to any algorithm which produces a solution having the fewest possible moves (i.e., the solver should not require any more than this number).

God's algorithm — main illustration
God's algorithm — illustration

Key takeaways

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

Reference excerpt

God's algorithm of the Rubik cube is a notion originating in discussions of ways to solve the Rubik's Cube puzzle, but which can also be applied to other combinatorial puzzles and mathematical games. It refers to any algorithm which produces a solution having the fewest possible moves (i.e., the solver should not require any more than this number). The allusion to the deity is based on the notion that an omniscient being would know an optimal step from any given configuration.

Scope

Definition The notion applies to puzzles that can assume a finite number of "configurations", with a relatively small, well-defined arsenal of "moves" that may be applicable to configurations and then lead to a new configuration. Solving the puzzle means to reach a designated "final configuration", a singular configuration, or one of a collection of configurations. To solve the puzzle a sequence of moves is applied, starting from some arbitrary initial configuration.

Solution An algorithm can be considered to solve such a puzzle if it takes as input an arbitrary initial configuration and produces as output a sequence of moves leading to a final configuration (if the puzzle is solvable from that initial configuration, otherwise it signals the impossibility of a solution). A solution is optimal if the sequence of moves is as short as possible. The highest value of this, among all initial configurations, is known as God's number, or, more formally, the minimax value. God's algorithm, then, for a given puzzle, is an algorithm that solves the puzzle and produces only optimal solutions. Some writers, such as David Joyner, consider that for an algorithm to be properly referred to as "God's algorithm", it should also be practical, meaning that the algorithm does not require extraordinary amounts of memory or time. For example, using a giant lookup table indexed by initial configurations would allow solutions to be found very quickly, but would require an extraordinary amount of memory. Instead of asking for a full solution, one can equivalently ask for a single move from an initial but not final configuration, where the move is the first of some optimal solution. An algorithm for the single-move version of the problem can be turned into an algorithm for the original problem by invoking it repeatedly while applying each move reported to the present configuration, until a final one is reached; conversely, any algorithm for the original problem can be turned into an algorithm for the single-move version by truncating its output to its first move.

Examples Well-known puzzles fitting this description are mechanical puzzles such as Rubik's Cube, the Tower of Hanoi, and the 15 puzzle. The one-person game of peg solitaire is also covered, as well as many logic puzzles, such as the missionaries and cannibals problem. These have in common that they can be modeled mathematically as a directed graph, in which the configurations are the vertices, and the moves are the arcs.

Mechanical puzzles

n-Puzzles The Fifteen puzzle can be solved in 80 single-tile moves or 43 multi-tile moves in the worst case. For its generalization the n-puzzle, the problem of finding an optimal solution is NP-hard, so it is not known whether there is a practical God's algorithm.

Towers of Hanoi For the Towers of Hanoi puzzle, a God's algorithm is known for any given number of disks. The number of moves increases exponentially with the number of disks ( 2 n − 1 {\displaystyle 2^{n}-1} ).

Rubik's Cube

An algorithm to determine the minimum number of moves to solve Rubik's Cube was published in 1997 by Richard E. Korf. While it had been known since 1995 that 20 was a lower bound on the number of moves for the solution in the worst case, Tom Rokicki proved in 2010 that no configuration requires more than 20 moves. Thus, 20 is a sharp upper bound on the length of optimal solutions. Mathematician David Singmaster had "rashly conjectured" this number to be 20 in 1980.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with God's algorithm

Start with the simplest possible case. Write down what God's 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 God's 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 God's 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 God's algorithm

In research
God's 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 God's 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
God's algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Logic puzzles, Mathematical games, Rubik's Cube, so understanding it makes those chapters shorter.
In everyday life
Look for God's 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.

Affiliate

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

How to study God's algorithm in 20 minutes

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

Frequently asked questions

What is God's algorithm in simple terms?

God's algorithm of the Rubik cube is a notion originating in discussions of ways to solve the Rubik's Cube puzzle, but which can also be applied to other combinatorial puzzles and mathematical games. It refers to any algorithm which produces a solution having the fewest possible moves (i.e., the so…

Why does God's 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 God's 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 God's algorithm.

Tags

  • Logic puzzles
  • Mathematical games
  • Rubik's Cube
  • Search algorithms

Keep exploring