Artificial Intelligence
From intelligent agents and search to adversarial search, CSPs, Bayesian networks, MDPs and
machine learning
Artificial Intelligence | Course Code: CS 221 | 2026-2027 Comprehensive Edition
WHAT’S INSIDE THIS GUIDE
✔ Chapter 1 — Intelligent agents and problem formalization ✔ Chapter 2 — Uninformed search strategies and complex
ity
✔ Chapter 3 — Informed search, heuristics and A star ✔ Chapter 4 — Adversarial search and alpha beta pruning
✔ Chapter 5 — Constraint satisfaction and propagation ✔ Chapter 6 — Propositional logic, CNF and resolution
✔ Chapter 7 — Bayesian networks and exact inference ✔ Chapter 8 — Markov decision processes and reinforce
ment learning
✔ Chapter 9 — Machine learning fundamentals and utility ✔ A 34 row formula Master Table with unit traps
✔ A ten problem worked set with full arithmetic ✔ A 20 question practice exam with step by step solutions
✔ Sixteen exam traps plus formula card, flashcards, glos
sary and derivations
How to Use This Guide
Artificial intelligence examinations reward a very specific skill: the ability to take a vague scenario and turn it into
a formal object you can compute with. A student who can recite the definition of a rational agent earns a small
fraction of the credit earned by a student who, given a taxi scenario, writes down the performance measure, the
environment properties, the actuators and the sensors, and then states which agent architecture is appropriate
and why. The habit that organise this entire guide is formalise first, compute second. Almost every question in
this subject is one of four formal objects wearing a disguise: a search problem, a constraint problem, a probabilistic
model, or a sequential decision problem. Your first job on any exam page is to name which one you are looking at.
The nine chapters form a deliberate chain of increasing abstraction. Chapters 1 through 3 build the single agent
search apparatus: formalise a problem, search blindly, then search with a heuristic. Chapter 4 changes the rules
by adding an opponent, so that a value must be backed up through alternating layers of maximisation and
minimisation. Chapter 5 removes time and optimality and asks only for any assignment that satisfies constraints,
which is why propagation replaces path cost. Chapters 6 and 7 introduce logic and probability as two different
languages for uncertain knowledge, with resolution and variable elimination as their respective inference engines.
Chapter 8 makes decisions sequential and stochastic through the Bellman equation, and Chapter 9 closes the
loop by asking how the agent can learn the model or the policy from data rather than being handed it. Read a
chapter, then cover the text and reproduce its three worked examples with pencil arithmetic; the numbers are
chosen so that every one can be reconstructed exactly, and reconstruction is the fastest way to find a sign error
before the examiner does.
Use the Master Table as a pre exam audit. Cover the third column and, for each entry, say aloud the mistake
an examiner can build a trap around. The worked problem set, practice exam and extended appendix problems
are graded in length to train written reasoning, not merely answer recognition. The Sixteen Deadly Exam Traps
address the conceptual confusions that separate a distinction level script from a bare pass: admissible versus
consistent, complete versus optimal, marginal versus conditional independence, model based versus model free,
and so on.
Three habits:
• Name the formal object before you calculate. Write “state, actions, transition model, goal test, cost” for
search; “variables, domains, constraints” for a constraint problem; “nodes, arcs, conditional tables” for a
Independent study aid. Not affiliated with or endorsed by any university or publisher. Page 1 of 32
,Artificial Intelligence · CS 221 Artificial Intelligence
Bayesian network; “states, actions, rewards, transitions” for a decision process. A correct label usually reveals
the correct formula.
• State the assumptions under which your method is valid. A star is optimal only under a stated heuristic
condition; uniform cost search needs non negative step costs; variable elimination is exact only for the graphical
model as given; value iteration assumes a known model and a discounted objective. Examiners award marks
for the boundary condition.
• Do the small hand computation before trusting the big idea. Trace three node expansions, prune one tree
branch, sum out one variable, run two iterations of value iteration. A single clean arithmetic line is worth more
than a paragraph of vague intuition and catches most direction errors.
KEY TAKEAWAY
Every problem in this course reduces to one of four moves: define a search problem and choose an
expansion order; define a constraint problem and propagate domains; define a probabilistic model and
condition or eliminate; or define a decision process and back up expected utility through the Bellman
equation. Identify the move, state the validity condition, then substitute numbers.
1 Quick-Reference Master Table
Quantity Formula and meaning Unit trap
Problem formulation Initial state, actions, transition model, goal Omitting the path cost function
test, path cost
State space at depth d Branching factor b gives b to the power d Writing d to the power b
nodes at depth d
BFS evaluation First in first out expands shallowest node; Claiming optimality on weighted
optimal for unit costs edges
BFS complexity Time O(b to the power d), space O(b to the Forgetting it stores the frontier
power d)
Iterative deepening Repeated depth limited DFS; optimal with Counting re expansion as
O(b d) space incompleteness
Uniform cost search Expand least g(n); optimal when every step Running it with negative edges
cost is positive
A star evaluation f(n) = g(n) + h(n), estimated total path cost Using h(n) alone
Admissible heuristic h(n) never exceeds the true optimal cost h Allowing one overestimate
star(n)
Consistent heuristic h(n) at most c(n,a,n2) + h(n2) for every arc Confusing consistency with
admissibility
A star optimality Optimal for trees if h admissible; for graphs if Assuming any heuristic is safe
h consistent
Greedy best first Expand smallest h(n); fast, neither complete Mistaking speed for correctness
nor optimal
Relaxed problem heuristic Exact cost of a relaxed problem is Using relaxed cost as an upper
admissible bound
Heuristic combination Taking the maximum of admissible heuristics Adding two admissible heuristics
stays admissible
Minimax recursion MAX node takes max over actions, MIN Applying max at a MIN node
node takes min over successors
Alpha bound alpha is the best MAX value found so far, a Updating alpha at MIN nodes
lower bound
Beta bound beta is the best MIN value found so far, an Swapping alpha and beta
upper bound
Alpha beta cutoff Prune a branch when beta is at most alpha Using a strict inequality at equality
Alpha beta order Best move first gives best case O(b to the Quoting best case as worst case
power d over 2)
Independent study aid. Not affiliated with or endorsed by any university or publisher. Page 2 of 32
,Artificial Intelligence · CS 221 Artificial Intelligence
Quantity Formula and meaning Unit trap
CSP definition Variables with domains plus constraints; a Accepting partial assignments
solution assigns all variables
Arc consistency Arc Xi to Xj consistent if each xi has a Checking only one direction
supporting xj
AC 3 rule Revise every arc; when a domain shrinks re Forgetting to re add arcs
add arcs Xk to Xi
Forward checking After assigning X prune inconsistent Not undoing pruning on backtrack
neighbour values
MRV heuristic Choose the unassigned variable with fewest Choosing the largest domain
legal values
CNF Conjunction of clauses, each clause a Confusing CNF with DNF
disjunction of literals
Resolution rule From A or B and not B or C infer A or C Resolving on two literals at once
Bayesian factorisation Joint equals product over i of P(Xi given Dropping the parent conditioning
Parents(Xi))
D separation X independent of Z given Y if every path is Ignoring explaining away
blocked
Bayes rule P(H given E) = P(E given H) P(H) divided by Swapping likelihood and posterior
P(E)
Variable elimination Multiply factors then sum out a variable by Summing out before multiplying
product of its factors
Bellman equation V(s) = max over a of R(s,a) + gamma times Omitting the discount gamma
expected V of next
Value iteration Synchronously replace V by the Bellman Updating in place and calling it exact
backup until it converges
Expected utility EU(a) = sum over outcomes of P(outcome Using probabilities without utilities
given a) times U(outcome)
Q learning update Q(s,a) increases by alpha times temporal Learning the policy instead of Q
difference error
2 Chapter 1 — Agents and Problem Formalization
An agent is anything that perceives its environment through sensors and acts upon that environment through
actuators. The definition is deliberately general: a human has eyes and hands, a robot has cameras and motors,
and a software agent has file reads and API calls as sensors and writes or requests as actuators. What makes
an agent rational is not that it is omniscient but that, for each possible percept sequence, it chooses the action
expected to maximise its performance measure given its own knowledge. Three qualifiers matter and are examined
relentlessly: the performance measure is whatever the designer specifies, not what seems intelligent to a human;
rationality is evaluated over the whole percept sequence, not a single action; and the agent must act despite
incomplete information, which is why the word expected appears. A question that asks whether an agent is
rational can only be answered once you are told the performance measure, because an action that looks foolish
under one measure can be optimal under another.
The environment must be typed before an architecture can be chosen, and there are six standard axes. Fully
observable versus partially observable asks whether the sensors give access to the complete state at each instant;
a vacuum agent with a position sensor and a dirt sensor on a two square floor is fully observable, while one without
a position sensor is not. Deterministic versus stochastic asks whether the next state is fixed by the current state
and action; a free throw is stochastic. Episodic versus sequential asks whether the current decision affects future
ones; a single spam classification is episodic, driving a car is sequential. Static versus dynamic asks whether the
environment changes while the agent deliberates. Discrete versus continuous concerns time, state and action
granularity. Single agent versus multi agent asks whether other agents’ goals matter. The hardest environment is
partially observable, stochastic, sequential, dynamic, continuous and multi agent; writing this list for the scenario
in the question is often worth several marks on its own.
Independent study aid. Not affiliated with or endorsed by any university or publisher. Page 3 of 32
,Artificial Intelligence · CS 221 Artificial Intelligence
Agent programs come in five families that form a progression of increasing generality. A simple reflex agent
selects actions solely on the current percept using condition action rules, and works only when the correct action
can be decided from the percept alone. A model-based reflex agent maintains an internal state representing the
unobserved parts of the world and updates it using a model of how the world evolves and how its own actions
affect it. A goal-based agent adds a description of desirable states and searches or plans toward them, which
is the bridge to Chapters 1 through 5. A utility-based agent attaches a scalar value to states and prefers higher
expected utility, which is the language of Chapters 8 and 9. A learning agent has a performance element that
selects actions plus a learning element that improves it from critic feedback, a problem generator that suggests
exploratory actions, and a model of the world that the learning element updates. Examiners commonly give a
behaviour and ask for the minimal architecture that could produce it; the answer is the least powerful family in this
list that suffices.
Problem solving agents make the goal based idea concrete with five components. The initial state is where the
agent starts. The actions describe what can be done; in a deterministic problem the transition model returns
the successor resulting from applying an action to a state, and together actions and model define the state space
graph. The goal test decides whether a state is a goal, and may be a single state or a predicate over states. The
path cost function assigns a numeric cost to each step, conventionally non negative, and the solution cost is
the sum. A solution is a sequence of actions taking the initial state to a goal state, and an optimal solution has
minimal cost among all solutions. It is essential to distinguish the state space graph, whose nodes are distinct
world states, from the search tree, whose nodes are paths; the same state can appear on many tree nodes, which
is exactly why graph search needs an explored set.
Choosing the state description is an art that examiners test through abstraction. For route finding, a state is a
city and an action is a road segment; for the eight puzzle, a state is an arrangement of eight numbered tiles and
a blank; for the travelling salesperson, a state is a city plus the set of cities already visited, because revisiting
matters. Including too much information explodes the state space, while including too little makes a valid plan
impossible. The five components are then handed to a generic search algorithm: formulate the problem, search for
a solution, and execute the solution in the real environment. This separation is the main reason search is reusable
across domains: the algorithm does not know whether it is moving a vacuum robot or proving a theorem, only that
states, actions, a goal test and a cost exist.
EXAM TIP
Exam move: whenever a scenario asks you to design an agent, write the four letters PEAS first —
Performance measure, Environment, Actuators, Sensors — then classify the environment on all six axes,
then name the weakest architecture that suffices. That single ordered routine converts an unstructured
essay question into a mark scheme you can tick off line by line.
2.1 Worked example 1.1 — PEAS description for an automated taxi
Task environment: an automated taxi that transports passengers between addresses in a city.
Performance measure. The designer must choose it explicitly. A reasonable composite is safety first, then
reaching the correct destination, then minimising fuel, time and passenger discomfort, and finally maximising profit.
Notice that these conflict: the fastest route may be the least safe, so the measure must encode a trade off, often
as a weighted sum with a very large penalty for collisions.
Environment. Roads, other drivers, pedestrians, traffic signals, weather, passengers and GPS signals. The
environment is partially observable because other drivers’ intentions are hidden; stochastic because traffic and
weather are unpredictable; sequential because today’s route affects tomorrow’s location and fuel; dynamic
because the world changes while the taxi plans; continuous in time and space; multi agent because other drivers
pursue their own goals.
Actuators. Steering, accelerator, brake, signal lights, horn, and a display or speaker for passenger communication.
Sensors. Cameras, radar or lidar, GPS receiver, speedometer, accelerometer, engine sensors, and a passenger
input interface.
Architecture check. Simple reflex rules such as “if red light then brake” are necessary but insufficient because the
correct action depends on hidden state and future goals. The taxi needs a model based component for tracking
Independent study aid. Not affiliated with or endorsed by any university or publisher. Page 4 of 32