Docsity

Artificial Intelligence notes - Padua University, Sbobinature di Tecniche Di Intelligenza Artificiale

Toggle sidebar
bg1
Federico Luisetto
Artificial Intelligence notes
Table of Contents:
What is AI? ............................................................................................................................................ 3
Computational Sustainability.................................................................................................................. 3
Agents and environments....................................................................................................................... 5
Agent ............................................................................................................................................................ 5
Rational agent .............................................................................................................................................. 5
PEAS ............................................................................................................................................................. 5
Environment types ....................................................................................................................................... 5
Agent types .................................................................................................................................................. 7
Stable matching problems ...................................................................................................................... 8
Matching under preferences ........................................................................................................................ 8
Stable Matching Problems............................................................................................................................ 8
Gale Shapley algorithm ................................................................................................................................ 9
Solving problems by searching .............................................................................................................. 12
Problem solving agent ................................................................................................................................ 12
Problem formulation .................................................................................................................................. 12
Uninformed search algorithms ................................................................................................................... 13
Informed search algorithms ....................................................................................................................... 15
Local search algorithms ........................................................................................................................ 17
Hill-climbing search .................................................................................................................................... 17
Simulated annealing search........................................................................................................................ 18
Local beam search ...................................................................................................................................... 18
Genetic algorithms ..................................................................................................................................... 18
Constraint Satisfaction Problems .......................................................................................................... 19
Backtracking search for CSPs ...................................................................................................................... 20
Backjumping ............................................................................................................................................... 21
No-good...................................................................................................................................................... 21
Forward checking ....................................................................................................................................... 22
Constraint propagation .............................................................................................................................. 22
Local search ................................................................................................................................................ 23
Structure of the problem ............................................................................................................................ 25
Soft Constraints .......................................................................................................................................... 28
Multi-agent decision making ................................................................................................................ 32
Preferences ................................................................................................................................................ 32
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Anteprima parziale del testo

Scarica Artificial Intelligence notes - Padua University e più Sbobinature in PDF di Tecniche Di Intelligenza Artificiale solo su Docsity!

Federico Luisetto

Artificial Intelligence notes

  • What is AI? Table of Contents:
  • Computational Sustainability..................................................................................................................
  • Agents and environments.......................................................................................................................
    • Agent
    • Rational agent
    • PEAS
    • Environment types
    • Agent types
  • Stable matching problems
    • Matching under preferences
    • Stable Matching Problems............................................................................................................................
    • Gale Shapley algorithm
  • Solving problems by searching..............................................................................................................
    • Problem solving agent
    • Problem formulation
    • Uninformed search algorithms
    • Informed search algorithms
  • Local search algorithms
    • Hill-climbing search
    • Simulated annealing search........................................................................................................................
    • Local beam search
    • Genetic algorithms
  • Constraint Satisfaction Problems
    • Backtracking search for CSPs
    • Backjumping
    • No-good......................................................................................................................................................
    • Forward checking
    • Constraint propagation
    • Local search
    • Structure of the problem
    • Soft Constraints
  • Multi-agent decision making
    • Preferences
    • Preferences in multi-agent decision making
    • Voting theory..............................................................................................................................................
  • Bayesian Networks
    • Syntax
    • Compactness
    • Semantics
    • Construction
    • Inference

social, environmental, and natural sciences, can drive computational sustainability in ways that

would not be possible in a smaller or less interdisciplinary setting.

Agents and environments

Agent

An agent is anything that can be viewed as perceiving its environment through sensors and acting upon

that environment through actuators. The agent function maps percept histories to actions [ 𝑓 ∶ 𝒫

∗

→ 𝒜 ].

The agent program runs on the physical architecture to produce 𝑓.

Vacuum-cleaner example.

Rational agent

An agent should strive to "do the right thing", based on what it can perceive and the actions it can perform.

The right action is the one that will cause the agent to be most successful. Performance measure: an

objective criterion for success of an agent's behavior. For each possible percept sequence, the rational

agent should select an action that is expected to maximize its performance measure:

  • given the evidence provided by the percept sequence.
  • given whatever built-in knowledge the agent has.

Rationality is distinct from omniscience (all-knowing with infinite knowledge). Agents can perform actions

in order to modify future percepts so as to obtain useful information (information gathering, exploration).

An agent is autonomous if its behavior is determined by its own experience (with ability to learn and

adapt). Ideally: equip an agent with some prior knowledge and the ability to learn.

PEAS

Task environments: the “problems” for which artificial agents are “solutions”. A task environment is

specified by PEAS (Performance measure, Environment, Actuators, Sensors). Must first specify the setting

for intelligent agent design. Example: taxi. Agent: an automated taxi driver.

  • Performance measure: Safe, fast, legal, comfortable trip, maximize profits.
  • Environment : Roads, other cars in the traffic, pedestrians, customers.
  • Actuators : Steering, accelerator, brake, signal, horn.
  • Sensors : Cameras, sonar, speedometer, GPS, engine sensors, keyboard.

Environment types

  • Fully observable / partially observable.

Fully observable if agent sensors give it access to the complete state of the environment at each

point in time. Partially observable because of noisy, inaccurate sensors. If there are no sensors, the

environment is unobservable.

  • Deterministic / stochastic.

Deterministic if the next state of the environment is completely determined by the current state

and the action executed by the agent. Strategic if the environment is deterministic except for the

actions of other agents. Stochastic if there is uncertainty on the next state and it is expressed with

probabilities. Non-deterministic if there is uncertainty on the next state but no probabilities are

available. Uncertain if not fully observable and non-deterministic.

  • Episodic / sequential.

Episodic if the agent's experience is divided into atomic "episodes”. Each episode consists of the

agent perceiving and performing a single action. The choice of action in each episode depends only

on the episode itself. Sequential if a current decision may affect future decisions.

  • Static / dynamic.

Static if the environment is unchanged while an agent is deliberating. No need to keep looking at

the world while deliberating the next action nor worrying about time. Dynamic if continuously

The Table-Driven-Agent program is invoked for each new percept, retains the complete percept sequence

in memory and returns an action each time.

→ Drawbacks: invoked for each new percept, huge table (chess: 10150 entries), takes a long time to build

the table, even with learning need a long time to learn the table entries, who knows how to build it?!

Agent types

Four basic types of agents in order of increasing generality:

  • Simple reflex agents select the action considering only the current percept.
  • Model-based reflex agents maintain internal state to track aspects of the world that are not

evident in the current percept.

  • Goal-based agents act to achieve their goals.
  • Utility-based agents try to maximize their own expected “happiness”.

Agent programs consist of various components. The components can represent the environment in three

ways:

i. Atomic representation :

a. Each state of the world is indivisible. It has no internal structure.

ii. Factored representation :

a. Each state contains a fixed set of variables (or attributes).

b. Each variable can have a value.

c. Two different factored states can share some variables.

iii. Structured representation :

a. Each state contains objects (with variables with values) and relations with other objects.

A more expressive representation can capture at least as concisely everything a less expressive one can

capture, plus some more.

Stable matching problems

Multi agent system is a collection of multiple intelligent agents which interact. Ideally, we would like

intelligent agents to be able to communicate and interact with other agents, so we build societies of

artificial agents by taking inspiration from groups of humans (economics, game theory, and social choice).

Computational social choice: an interdisciplinary field at the interface of artificial intelligence, economics,

voting theory, game theory and social choice. We will see one problem in this area, the matching problems,

that are a mathematical abstraction of two-sided markets.

Matching under preferences

Matching problems under preferences have been studied widely in mathematics, computer science and

economics. Matching problems with preferences occur in widespread applications (school-leavers to

universities, junior doctors to hospitals, children to schools).

The common thread is that individuals have preferences over the possible outcomes and the task is to find

a matching of the participants that is in some sense optimal with respect to these preferences.

List of topics:

  • Two-sided matchings involving agents on both sides (e.g., college admissions, medical resident

allocation, job markets, and school choice).

  • Two-sided matchings involving agents and objects (e.g., house allocation, course allocation,

project allocation, assigning papers to reviewers, and school choice).

  • One-sided matchings (e.g., roommate problems, coalition formation games, and kidney exchange).
  • Other recent applications (e.g., refugee resettlement, food banks, social housing, and daycare).

Stable Matching Problems

Two sets of agents. Agents of one set express preferences over agents of the other set. The goal is to

choose a matching among the agents of the two sets based on their preferences. Matching: set of pairs

1

2

, where 𝐴

1

comes from the first set and 𝐴

2

comes from the second set.

Stable Marriage formulation

  • Two sets of agents: men and women.
  • Idealized model:

o Same number of men and women.

o All men totally order all women, and vice versa.

Stable Marriage problem

  • Given preferences of 𝑛 men:

o Greg: Amy>Bertha>Clare.

o Harry: Bertha>Amy>Clare.

o Ian: Amy>Bertha>Clare.

  • Given preferences of 𝑛 women:

o Amy: Harry>Greg>Ian.

o Bertha: Greg>Harry>Ian.

o Clare: Greg>Harry>Ian.

Find a stable marriage. Marriage is a one-to-one correspondence between men and women. Stable

marriage is a marriage with no pair

not married to each other that would prefer to be

together. Blocking pair is a pair (𝑚, 𝑤), where 𝑚 is a man and 𝑤 is a woman such that the marriage

contains

and

, but 𝑚 prefers 𝑤 to 𝑤’, and 𝑤 prefers 𝑚 to 𝑚’.

  • Existence :

o strongly stable marriage may not exist → 𝑂

4

algorithm for deciding existence.

o weakly stable marriage always exists:

▪ just break ties arbitrarily.

▪ run GS, resulting marriage is weakly stable! → polynomial complexity.

Incomplete preferences:

  • Model unacceptability of an option → one of the Rovers does not have a camera.
  • More possible blocking pairs.
  • (𝑚, 𝑤) blocking pair if:

o 𝑚 and 𝑤 are unmatched and do not find each other unacceptable.

o 𝑚, 𝑤 both prefer each other to current partners.

o one of the two is matched but acceptable to the other and prefers the other who is

unmatched.

  • GS algorithm extends easily → Polynomial complexity.
  • The set of unmatched elements is the same in every stable marriage.

Weakly stable marriages may have different sizes. Unlike with just ties where they are all complete or with

just incompleteness where the cardinality is fixed.

Finding weakly stable marriage of maximal cardinality is NP-hard even if only men declare ties, ties are of

most of length two and the whole list is a tie.

GS is strategy proof (that is, non-manipulable) for men. Assuming male optimal algorithm no man can do

better than the male optimal solution. However, women can profit from lying (that is, women can obtain a

better partner by expressing different preferences from the true ones)

  • Assuming male optimal algorithm is run.
  • Assuming they know complete preference lists.

Manipulation by women

  • Greg: Amy > Bertha > Clare
  • Harry: Bertha > Amy > Clare
  • Ian: Amy > Bertha > Clare
  • Amy: Harry > Greg > Ian
  • Bertha: Greg > Harry > Ian
  • Clare: Greg > Harry > Ian
    • Greg: Amy > Bertha > Clare
    • Harry: Bertha > Amy > Clare
    • Ian: Amy > Bertha > Clare
  • Amy: Harry > Ian > Greg
  • Bertha: Greg > Harry > Ian
  • Clare: Greg > Harry > Ian

Result of running GS on true preferences Result of running GS on manipulated preferences

→ GS can be manipulated. Every stable marriage procedure (that is, every procedure that returns a stable

marriage) can be manipulated if preference lists can be incomplete. Proof:

Consider:

1

1

2

1

2

1

2

2

1

2

1

2

Two stable marriages:

1

1

2

2

1

2

2

1

Amy lies

Suppose we get male optimal solution → {(𝑚

1

1

2

2

If woman 𝑤 1

lies and says 𝑚

1

is unacceptable then we must get {(𝑚

1

2

2

1

)} as this is the only

stable marriage. Any procedure that returns a stable matching can be manipulated if preference lists can be

incomplete. Other cases can be manipulated in a similar way.

  • Goal test allows to check if a state is a goal.
  • Path cost is a numeric value associated to each path reflecting the desired performance measure:

o e.g., sum of distances, number of actions executed, etc.

o 𝑐(𝑥, 𝑎, 𝑦) is the step cost, for going from state 𝑥 to state 𝑦 by performing action 𝑎.

o Assumed to be ≥ 0.

o We assume path costs to be additive: sum of step costs.

Solution : sequence of actions (path) leading from the initial state to a goal state.

Optimal solution : a solution with minimal path-cost.

Problem state space = (initial state, actions, transition model).

State space = the set of all states reachable from the initial state by any sequence of actions.

The state space can be depicted as a directed graph:

  • nodes → states.
  • edges → actions.
  • path → sequence of states connected by a sequence of actions.

Romania example

Vacuum world example

The 8-puzzle example

Uninformed search algorithms

After defining problems, we need to solve them. A solution is a sequence of actions (path) leading from the

initial state to a goal state.

Tree search algorithm

Search algorithms consider possible sequences of actions. Possible sequences of actions starting from initial

state form a search tree, where the root corresponds to the initial state, the nodes to the states and the

branches to the actions. The same state can appear multiple times! Outgoing edges from a node represent

all possible actions available in the state represented by the node.

Leaf node: a node with no children in the tree.

Frontier: the set of all leaf nodes available for expansion at any given point.

function 𝑇𝑅𝐸𝐸 − 𝑆𝐸𝐴𝑅𝐶𝐻

returns a solution, or failure

initialize the frontier using the initial state of problem

loop do

if the frontier is empty then return failure

choose a leaf node and remove it from the frontier

if the node contains a goal state then return the corresponding solution

expand the chosen node, adding the resulting nodes to the frontier

A redundant path exists whenever there is more than one way to get from one state to another. A loopy

path is a special case of a redundant path.

To avoid exploring redundant paths 𝑇𝑅𝐸𝐸 − 𝑆𝐸𝐴𝑅𝐶𝐻 algorithm is augmented with explored set that

remembers every expanded node.

Graph search algorithm

function 𝐺𝑅𝐴𝑃𝐻 − 𝑆𝐸𝐴𝑅𝐶𝐻

returns a solution, or failure

initialize the frontier using the initial state of problem

initialize the explored set to be empty

loop do

if the frontier is empty then return failure

choose a leaf node and remove it from the frontier

if the node contains a goal state then return the corresponding solution

add the node to the explored set

expand the chosen node, adding the resulting nodes to the frontier

only if not in the frontier or explored set

Infrastructure for search algorithms

Search algorithms require a data structure to keep track of the search tree. For each node 𝑛 of the tree, we

have a structure with:

  • 𝑛. 𝑆𝑇𝐴𝑇𝐸: the state in the state space to which the node corresponds.
  • 𝑛. 𝑃𝐴𝑅𝐸𝑁𝑇: the node in the search tree that generated this node.
  • 𝑛. 𝐴𝐶𝑇𝐼𝑂𝑁: the action that was applied to the parent to generate the node.
  • 𝑛. 𝑃𝐴𝑇𝐻 − 𝐶𝑂𝑆𝑇: the cost, traditionally denoted by 𝑔(𝑛), of the path from the initial state to the

node, as indicated by the parent pointers.

A state corresponds to a configuration of the world, a node is a data structure used to represent the search

tree.

A frontier needs to be stored in such a way that the search algorithm can easily choose the next node to

expand, so the appropriate data structure for this is a queue.

Operations on a queue:

  • 𝐸𝑀𝑃𝑇𝑌? (𝑞𝑢𝑒𝑢𝑒) returns true only if there are no more elements in the queue.
  • 𝑃𝑂𝑃(𝑞𝑢𝑒𝑢𝑒) removes the first element of the queue and returns it.
  • 𝐼𝑁𝑆𝐸𝑅𝑇(𝑒𝑙𝑒𝑚𝑒𝑛𝑡, 𝑞𝑢𝑒𝑢𝑒) inserts an element and returns the resulting queue.

Queues are characterized by the order in which they store the inserted nodes. Three common variants:

i. FIFO queue, which pops the oldest element of the queue.

ii. LIFO queue, which pops the newest element of the queue.

iii. Priority queue, which pops the element of the queue with the highest priority according to

some ordering function.

Search strategies

A search strategy is defined by picking the order of node expansion. Strategies are evaluated along the

following dimensions:

  • completeness: does it always find a solution if one exists?
  • time complexity: number of nodes generated.
  • space complexity: maximum number of nodes in memory.
  • optimality: does it always find a least-cost solution?

Properties:

  • Complete? Yes (unless there are infinitely many nodes with 𝑓 ≤ 𝑓
  • Time? Exponential.
  • Space? Keeps all nodes in memory.
  • Optimal? Yes (with TREE-SEARCH, admissible heuristic; GRAPH-SEARCH, consistent heuristic).

Heuristics

A heuristic ℎ is admissible if for every node 𝑛, ℎ(𝑛) ≤ ℎ

∗

(𝑛) where ℎ

∗

(𝑛) is the true cost from 𝑛 to goal.

An admissible heuristic never overestimates the cost to reach the goal.

Theorem : If ℎ is admissible, A* using 𝑇𝑅𝐸𝐸 − 𝑆𝐸𝐴𝑅𝐶𝐻 is optimal.

A heuristic ℎ is consistent if for every node 𝑛, for every successor 𝑛′ of 𝑛 generated by an action 𝑎 , ℎ(𝑛) ≤

′

) + ℎ(𝑛’) → instance of triangular inequality. Consistency → admissibility.

Theorem : If ℎ is consistent A* using 𝐺𝑅𝐴𝑃𝐻 − 𝑆𝐸𝐴𝑅𝐶𝐻 is optimal.

Given two heuristics ℎ 1

and ℎ

2

, if ℎ

2

1

(𝑛) for all node 𝑛 (both admissible) then ℎ

2

dominates ℎ

1

2

is better than ℎ

1

for search, so ℎ

1

will expand all the nodes ℎ

2

expands and possibly more.

A problem with fewer restrictions on actions is called a relaxed problem. A superset of actions is available

from each state → the graph of the relaxed problem is a supergraph of the original.

Any optimal solution of the original problem is also a solution of the relaxed problem, and the cost of an

optimal solution of the relaxed problem may be the same or lower than the cost of an optimal solution of

the original problem.

→ The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.

Admissible heuristics can be derived from the exact solution cost of a relaxed version of the problem.

Local search algorithms

In many optimization problems the path from the start node to the goal is irrelevant and the goal state

itself is the solution. A state space is the set of "complete" configurations that satisfy constraints. In such

cases, we can use local search algorithms keeping a single "current" state and trying to improve it.

n - queens example

Local search algorithms explore the state-space landscape.

A landscape has:

  • location (defined by the state).
  • elevation (defined by the value of heuristic cost function or objective function).

The aim is to find:

  • a global minimum (lowest valley) if elevation corresponds to cost.
  • a global maximum (highest peak) if elevation corresponds to objective function.

Hill-climbing search

Assume the elevation corresponds to the objective function, Hill-climbing search modifies the current state

to try to improve it.

function 𝐻𝐼𝐿𝐿 − 𝐶𝐿𝐼𝑀𝐵𝐼𝑁𝐺(𝑝𝑟𝑜𝑏𝑙𝑒𝑚) returns a state that is a local maximum

current ← 𝑀𝐴𝐾𝐸 − 𝑁𝑂𝐷𝐸

loop do

neighbor ← a highest-valued successor of current

if neighbor.VALUE ≤ current.VALUE then return current.STATE

current ← neighbor

The algorithm picks a neighbor with the highest value. Usually chooses at random among neighbors with

maximum value and terminates when it reaches a “peak” where no neighbor has a higher value.

Hill climbing often gets stuck for the following reasons:

  • Local maxima : a peak that is higher than each of its neighboring states, but lower than the global

maximum.

  • Plateaux : a flat area of the state-space landscape

o flat local maximum , from which no progress is possible.

o shoulder , from which progress is possible.

Hill climbing variants:

  • Stochastic hill climbing: chooses at random from the set of all improving neighbors.
  • First-choice hill climbing: jumps to the first improving neighbor found.
  • Random-restart hill climbing: series of hill climbing runs until a goal is found. It will find a good

solution very quickly.

Hill-climbing algorithm that never makes “downhill” moves toward states with lower value is incomplete

because it can get stuck on a local maximum.

Purely random walk : moving to a successor chosen uniformly at random from the set of successors is

complete but extremely inefficient.

Idea → combine hill climbing with a random walk that yields both efficiency and completeness.

Constraint Satisfaction Problems

In standard search problems, the states are atomic (“black box” with no internal structure), evaluated by

domain-specific heuristics and tested to see whether they are goal states.

In CSPs there is a factored representation for each state:

  • State is defined by variables 𝑋

𝑖

with values from domain 𝐷

𝑖

  • Goal test is a set of constraints specifying allowable combinations of values for subsets of variables.
  • Solution : one value for each variable that satisfies all the constraints.

CSP allows useful general-purpose algorithms to solve complex problems with more power than standard

search algorithms and with general-purpose heuristics rather than problem-specific heuristics.

The main idea of algorithms for solving CSPs is to eliminate large portions of the search space all at once by

identifying variable/value combinations that violate the constraints.

Components:

  • Set of variables 𝑋 = {𝑋

1

2

𝑛

  • Set of domains 𝐷 = {𝐷

1

2

𝑛

o Each domain 𝐷

𝑖

consists of a set of allowable values for variable 𝑋

𝑖

o In many cases the domain is assumed to be the same for all variables.

  • Set of constraints 𝐶 = {𝑐

𝑖

𝑖

𝑖

o 𝑠𝑐𝑜𝑝𝑒

𝑖

: subset of 𝑋, the variables that are constrained by 𝑐

𝑖

o 𝑟𝑒𝑙

𝑖

: is a relation and tells us which simultaneous assignments of values to variables in

𝑖

are allowed.

  • State : defined by an assignment of values to some or all of the variables, {𝑋

𝑖

𝑖

𝑗

𝑗

  • Assignment can be:

o Consistent: it does not violate any constraints.

o Complete: every variable is assigned.

o Partial: only some of the variables are assigned.

  • Solution : a consistent and complete assignment.

Map-Coloring example

In a constraint graph, nodes are the variables and arcs show the constraints.

We formulate a problem as a CSP because it is a natural representation for many problems. We already

have a CSP-solving system → it is often easier to solve a problem using it than to design a custom solution

using another search technique.

CSP solvers are faster than state-space searchers because the CSP solver can quickly eliminate large parts of

the search space by constraint propagation.

Varieties of CSPs:

  • Discrete variables:

o Finite domains: 𝑛 variables, domain size 𝑑.

o Infinite domains: integers, strings, etc.

o e.g., job scheduling, variables are start/end days for each job.

o Constraints: StartJob 1

  • 5 ≤ StartJob
  • Continuous variables:

o Common in the real-world problems, studied in the field of operations research.

The simplest kind of CSP involves variables with discrete finite domains.

Varieties of constraints:

  • Unary constraints involve a single variable.
  • Binary constraints involve pairs of variables.
  • Higher-order constraints involve 3 or more variables.
  • Global constraints involve an arbitrary number of variables.

Any CSP can be converted into a CSP with only binary constraints.

Cryptarithmetic example

3 - SAT example

4 - Queens problem

Some real-world CSPs: assignment problems (e.g., who teaches what class), timetabling problems (e.g.,

which class is offered when and where?), transportation scheduling, factory scheduling and many real-

world problems involve real-valued variables.

Backtracking search for CSPs

Standard search formulation: let's start with the straightforward approach, then improve it:

  • Initial state : the empty assignment { }.
  • Successor function : assign a value to an unassigned variable that does not conflict with current

assignment → fail if no legal assignments.

  • State : partial assignment.
  • Goal test : the current assignment is complete.

This is the same for all CSPs. Every solution appears at depth 𝑛 with 𝑛 variables → use depth-first search.

We could use depth-first search, but for a CSP with 𝑛 variables of domain size 𝑑 we have that the branching

factor (maximum number of successors of a node) 𝑏 is:

i. at 1

𝑠𝑡

level: 𝑛𝑑 because any of 𝑑 values can be assigned to any of 𝑛 variables.

ii. at 2

𝑛𝑑

level: (𝑛 − 1 )𝑑.

iii. ...

iv. at 𝑛

𝑡ℎ

level: 𝑑.

We generate a tree with 𝑛! ∙ 𝑑

𝑛

leaves, even if only 𝑑

𝑛

possible complete assignments.

In CSPs, variable assignments are commutative. Thus, we need only consider a single variable at each level

in the search tree → 𝑏 = 𝑑, so the number of leaves is 𝑑

𝑛

Backtracking search = Depth-first search for CSPs with single-variable assignments.

→ A depth-first search that chooses values for SEARCH one variable at a time and backtracks when a

variable has no legal values left to assign.

function 𝐵𝐴𝐶𝐾𝑇𝑅𝐴𝐶𝐾𝐼𝑁𝐺 − 𝑆𝐸𝐴𝑅𝐶𝐻(𝑐𝑠𝑝) returns a solution, or failure

return 𝐵𝐴𝐶𝐾𝑇𝑅𝐴𝐶𝐾( { }, 𝑐𝑠𝑝 )

function 𝐵𝐴𝐶𝐾𝑇𝑅𝐴𝐶𝐾(𝑎𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡, 𝑐𝑠𝑝) returns a solution, or failure

if assignment is complete then return assignment

var ← 𝑆𝐸𝐿𝐸𝐶𝑇 − 𝑈𝑁𝐴𝑆𝑆𝐼𝐺𝑁𝐸𝐷 − 𝑉𝐴𝑅𝐼𝐴𝐵𝐿𝐸(𝑐𝑠𝑝)

for each value in 𝑂𝑅𝐷𝐸𝑅 − 𝐷𝑂𝑀𝐴𝐼𝑁 − 𝑉𝐴𝐿𝑈𝐸𝑆(𝑣𝑎𝑟, 𝑎𝑠𝑠𝑖𝑔𝑛𝑚𝑒𝑛𝑡, 𝑐𝑠𝑝) do