ArticleslgStudy

computer science

Look-ahead (backtracking)

Look-ahead (backtracking) 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 Look-ahead (backtracking) rather than just read about it. In short: In backtracking algorithms, look ahead is the generic term for a subprocedure that attempts to foresee the effects of choosing a branching variable to evaluate one of its values. The two main aims of look-ahead are to choose a variable to evaluate next and to choose the order of values to assign to it.

Look-ahead (backtracking) — main illustration
Look-ahead (backtracking) — illustration

Key takeaways

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

Reference excerpt

In backtracking algorithms, look ahead is the generic term for a subprocedure that attempts to foresee the effects of choosing a branching variable to evaluate one of its values. The two main aims of look-ahead are to choose a variable to evaluate next and to choose the order of values to assign to it.

Constraint satisfaction In a general constraint satisfaction problem, every variable can take a value in a domain. A backtracking algorithm therefore iteratively chooses a variable and tests each of its possible values; for each value the algorithm is recursively run. Look ahead is used to check the effects of choosing a given variable to evaluate or to decide the order of values to give to it.

Look ahead techniques

The simpler technique for evaluating the effect of a specific assignment to a variable is called forward checking. Given the current partial solution and a candidate assignment to evaluate, it checks whether another variable can take a consistent value. In other words, it first extends the current partial solution with the tentative value for the considered variable; it then considers every other variable x k {\displaystyle x_{k}} that is still unassigned, and checks whether there exists an evaluation of x k {\displaystyle x_{k}} that is consistent with the extended partial solution. More generally, forward checking determines the values for x k {\displaystyle x_{k}} that are consistent with the extended assignment.

A look-ahead technique that may be more time-consuming but may produce better results is based on arc consistency. Namely, given a partial solution extended with a value for a new variable, it enforces arc consistency for all unassigned variables. In other words, for any unassigned variables, the values that cannot consistently be extended to another variable are removed. The difference between forward checking and arc consistency is that the former only checks a single unassigned variable at a time for consistency, while the second also checks pairs of unassigned variables for mutual consistency. The most common way of using look-ahead for solving constraint satisfaction problems is the maintaining arc-consistency (MAC) algorithm. Two other methods involving arc consistency are full and partial look ahead. They enforce arc consistency, but not for every pair of variables. In particular, full look considers every pair of unassigned variables x i , x j {\displaystyle x_{i},x_{j}} , and enforces arc consistency between them. This is different than enforcing global arc consistency, which may possibly require a pair of variables to be reconsidered more than once. Instead, once full look ahead has enforced arc consistency between a pair of variables, the pair is not considered any more. Partial look ahead is similar, but a given order of variables is considered, and arc consistency is only enforced once for every pair x i , x j {\displaystyle x_{i},x_{j}} with i < j {\displaystyle i<j} . Look ahead based on arc consistency can also be extended to work with path consistency and general i-consistency or relational arc consistency.

Use of look ahead The results of look ahead are used to decide the next variable to evaluate and the order of values to give to this variable. In particular, for any unassigned variable and value, look-ahead estimates the effects of setting that variable to that value. The choice of the next variable and the choice of the next value to give it are complementary, in that the value is typically chosen in such a way that a solution (if any) is found as quickly as possible, while the next variable is typically chosen in such a way unsatisfiability (if the current partial solution is unsatisfiable) is proven as quickly as possible. The choice of the next variable to evaluate is particularly important, as it may produce exponential differences in running time. In order to prove unsatisfiability as quickly as possible, variables leaving few alternatives after being assigned are the preferred ones. This idea can be implemented by checking only satisfiability or unsatisfiability of variable/value pairs. In particular, the next variable that is chosen is the one having a minimal number of values that are consistent with the current partial solution. In turn, consistency can be evaluated by simply checking partial consistency, or by using any of the considered look ahead techniques discussed above. The following are three methods for ordering the values to tentatively assign to a variable:

min-conflicts: the preferred values are those removing the least total values from the domain of unassigned variables as evaluated by look ahead; max-domain-size: the preferred values are those maximising the number of values in the smallest domain they produce for the unassigned variables, as evaluated by look ahead; estimate solutions: the preferred values are those producing the maximal number of solutions, as evaluated by look ahead making the assumption that all values left in the domains of unassigned variables are consistent with each other; in other words, the preference for a value is obtained by multiplying the size of all domains resulting from look ahead. Experiments proved that these techniques are useful for large problems, especially the min-conflicts one. Randomization is also sometimes used for choosing a variable or value. For example, if two variables are equally preferred according to some measure, the choice can be done randomly.

References

Dechter, Rina (2003). Constraint Processing. Morgan Kaufmann. ISBN 1-55860-890-7 Ouyang, Ming (1998). "How Good Are Branching Rules in DPLL?". Discrete Applied Mathematics. 89 (1–3): 281–286. doi:10.1016/S0166-218X(98)00045-6.

Illustrations

Look-ahead (backtracking): Forward checking only checks whether each of the unassigned variables x3 and x4 is consistent with the partial assignment, removing the value 2 from their domains.
Forward checking only checks whether each of the unassigned variables x3 and x4 is consistent with the partial assignment, removing the value 2 from their domains.
Look-ahead (backtracking): Arc consistency look ahead also checks whether the values of x3 and x4 are consistent with each other (red lines) removing also the value 1 from their domains.
Arc consistency look ahead also checks whether the values of x3 and x4 are consistent with each other (red lines) removing also the value 1 from their domains.

Worked examples

Example 1 — a first encounter with Look-ahead (backtracking)

Start with the simplest possible case. Write down what Look-ahead (backtracking) 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 Look-ahead (backtracking) 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 Look-ahead (backtracking) 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 Look-ahead (backtracking)

In research
Look-ahead (backtracking) 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 Look-ahead (backtracking) 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
Look-ahead (backtracking) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Constraint programming, Search algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Look-ahead (backtracking) 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 “Look-ahead (backtracking)” →

Affiliate

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

How to study Look-ahead (backtracking) in 20 minutes

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

Frequently asked questions

What is Look-ahead (backtracking) in simple terms?

In backtracking algorithms, look ahead is the generic term for a subprocedure that attempts to foresee the effects of choosing a branching variable to evaluate one of its values. The two main aims of look-ahead are to choose a variable to evaluate next and to choose the order of values to assign to…

Why does Look-ahead (backtracking) 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 Look-ahead (backtracking)?

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 Look-ahead (backtracking).

Tags

  • Constraint programming
  • Search algorithms

Keep exploring