Guide to AI and Data Courses · Lecture Notes
Chapter 2: Artificial Intelligence
When we tell a warehouse robot to go from shelf A to shelf B, it has a map, a goal and hundreds of possible routes. We do not draw the route; the robot chooses it. Artificial intelligence is the course about that choosing: designing an agent that perceives its environment and finds the action that best serves its goal. Sometimes the choice is made by searching through paths, sometimes by logical inference, and sometimes by computing probabilities from incomplete information. These notes introduce the course and work through its three core ideas with small examples you can compute by hand.
Learning outcomes
- Agent and environment
- Describe a problem by its sensors, actuators, environment and performance measure; classify an environment by properties such as observability and determinism.
- Rationality
- Compute the performance of a simple agent under a measure and compare two agents by it.
- Search
- Trace breadth-first search and A* by hand on a small graph; check whether a heuristic function is admissible.
- Uncertainty
- Update a belief with a new observation using Bayes' rule and choose the action with the highest expected utility.
- Place of the course
- State what separates artificial intelligence from machine learning, expert systems, optimization and multi-agent systems.
2.1What question does the course ask?
How does a machine act intelligently by searching, reasoning and planning?
Artificial intelligence studies how to design intelligent agents that perceive their environment and choose the action that best serves their goal. The course brings search, logical inference, probabilistic reasoning, planning and learning into one framework. Machine learning is part of that framework, not all of it.
An AI course does not teach a single algorithm; it teaches a point of view: seeing intelligent behavior as a loop between an agent and its environment. The agent perceives, chooses an action based on what it knows, carries it out, and the environment changes. The rest of the course lists what can stand behind the word "chooses": searching states systematically, deriving conclusions from rules, reasoning with probability, or building a sequence of actions.
Two consequences of this view matter. First, "intelligent" is tied to a measure: an agent is rational if it tries to maximize the performance measure it was given. Whether it thinks like a human stays in the background. Second, the same agent framework describes very different problems in one language: a chess engine, a route planner and a diagnosis system are all agents that choose actions from what they perceive; only their environments and measures differ.
2.1.1Every problem starts with an environment
Before choosing an algorithm for a problem, we question its environment. Can the agent see all of it? Is the outcome of an action certain, or does it depend on chance? Does the environment change while the agent is thinking? The answers decide which technique will work: in a fully observable, deterministic environment search is enough; in a partially observable or random one we need probability. The three core sections below follow this order: agent and measure first, then search, then uncertainty.
2.1.2At a glance
| Criterion | Artificial Intelligence |
|---|---|
| Approach | search, logic, probability and learning combined |
| Input | problem definition: states, actions, goal |
| Output | action sequence, plan or decision |
| Success measure | reaching the goal, cost, rationality |
| Math load | medium: logic, probability, graphs |
| Data needs | little; often a model and knowledge suffice |
2.2A short history
| Year | Milestone |
|---|---|
| 1950 | Turing proposes the imitation game (the Turing test) in "Computing Machinery and Intelligence". |
| 1956 | Dartmouth summer workshop: the name "artificial intelligence" is coined and the field is born. |
| 1980s | Expert systems (MYCIN, XCON) go commercial; unmet expectations bring an "AI winter". |
| 1997 | Deep Blue beats Kasparov at chess: powerful search and a hand-written evaluation. |
| 2016 | AlphaGo beats Lee Sedol at Go: tree search, deep networks and reinforcement learning together. |
| 2022 | Large language models reach a mass audience through chat interfaces. |
2.3Core concepts
The rest of the course is built on the concepts below. The following sections work through the most important ones with examples.
| Concept | Meaning |
|---|---|
| Intelligent agent | Perceives the environment through sensors, acts on it through actuators. |
| Rationality | Choosing the action expected to maximize the performance measure. |
| State-space search | BFS, DFS, A*; heuristic functions. |
| Adversarial search | Minimax and alpha-beta pruning in games. |
| Constraint satisfaction | Variables, domains, constraints: Sudoku, timetabling. |
| Logic and knowledge | Propositional and first-order logic, inference rules. |
| Uncertainty | Bayes' rule, Bayesian networks, decision theory. |
| Planning | Building a sequence of actions from start to goal. |
2.4Intelligent agents and rationality
An agent is anything that perceives its environment through sensors and acts on it through actuators. Its behavior is an agent function: a mapping from the sequence of percepts so far to an action. A common template for describing an agent is known as PEAS: performance measure, environment, actuators, sensors.
For each percept sequence, a rational agent selects the action that is expected to maximize the expected value of its performance measure, given what it has perceived so far. Rationality does not mean knowing everything or never making mistakes; it means doing the best with the information at hand.
| Element | Robot vacuum example |
|---|---|
| Performance measure | number of clean squares at each time step |
| Environment | a two-square room (A and B), each square dirty or clean |
| Actuators | suck, move to the other square |
| Sensors | which square it is in and whether that square is dirty |
The room has two squares. The robot starts in A and both squares are dirty. There are four time steps; at the end of each step the number of clean squares is scored. We try three agents:
- Reflex agent: if its square is dirty it sucks, otherwise it moves to the other square. Step 1: sucks A, clean squares 1. Step 2: moves to B, clean 1. Step 3: sucks B, clean 2. Step 4: moves to A, clean 2. Total 1 + 1 + 2 + 2 = 6.
- Always-suck agent: never moves, sucks A. Clean squares 1 at every step. Total 4 × 1 = 4.
- Always-move agent: never sucks. Clean squares always 0. Total 0.
By this measure the ranking is reflex (6), always-suck (4), always-move (0). A simple rule is rational when it serves the measure well; but the same rule may not score the same in another environment, for example a room where dirt reappears. An agent is judged together with its environment.
The properties of an environment tell us how complex the agent must be. Let us compare four commonly asked questions for two environments.
| Property | Chess | Driving a taxi |
|---|---|---|
| Is the environment fully observable? | yes, the board is in view | no, other drivers' intentions are hidden |
| Is the outcome of an action certain? | yes | no, traffic and road conditions are random |
| Does the environment change while the agent thinks? | no (without a clock) | yes, traffic keeps moving |
| Are the states discrete? | yes | no, position and speed are continuous |
This is why chess suits search, while driving a taxi needs perception, prediction and probability. The order of the course follows it: fully observable, deterministic environments first, then uncertainty.
Choosing a performance measure that rewards what is easy to measure rather than what we want. If we score the robot above by "amount of dirt sucked", a robot that dumps dirt and sucks it up again gets the highest score and the room is never cleaned. The measure should reward the desired state of the environment (clean squares), not how the agent behaves.
2.5State-space search and A*
When the environment is fully observable and actions are certain, the agent can try out the outcome in its head. The problem is set up as a state space: an initial state, the actions available in each state with their costs, and a goal test. A solution is a sequence of actions from the start to the goal; search expands states systematically to find it. Uninformed searches look only at cost: breadth-first search (BFS) finds the path with the fewest actions, uniform-cost search the cheapest path. A* also uses a heuristic function that estimates how far the goal still is.
For each node we compute f(n) = g(n) + h(n), where g(n) is the cost so far from the start to n and h(n) is an estimate of the remaining cost from n to the goal. At every step the node with the smallest f is expanded. If h never overestimates the true cost (it is admissible), A* finds the cheapest path.
Edge costs: S–A 1, S–B 4, A–B 2, A–G 12, B–G 5. Start S, goal G. Heuristic values h(S) = 7, h(A) = 6, h(B) = 5, h(G) = 0. The true remaining costs are 8 from S, 7 from A and 5 from B, so no h value exceeds them: h is admissible.
- Expand S (f = 0 + 7 = 7). Neighbors: A, g = 1, f = 1 + 6 = 7; B, g = 4, f = 4 + 5 = 9.
- Expand A (smallest f = 7). Reaching B through A is cheaper: g = 1 + 2 = 3, f = 3 + 5 = 8. G gets g = 1 + 12 = 13, f = 13.
- Expand B (f = 8). G through B: g = 3 + 5 = 8, f = 8, better than the earlier 13.
- Expand G (f = 8) and the goal is found. The path is S → A → B → G with cost 8.
Comparison: BFS looks for the fewest actions; S → A → G (cost 13) and S → B → G (cost 9) have two actions each, while the cheapest path (8) has three and looks worse to it. Greedy search, which looks only at h, picks B after S because its h is smaller and reaches G at cost 9. A* adds g and h and finds the cheapest path, 8.
2.5.1How is a heuristic chosen?
A good h is close to the truth but never above it. For a robot moving on a grid, Manhattan distance is an admissible estimate, because obstacles can only lengthen the path. The same holds for the 8-puzzle: sum each tile's distance to its goal square (row difference + column difference). The closer h is to the truth, the fewer nodes A* expands. If h is always 0, A* becomes uniform-cost search.
Choosing a generous heuristic "to be a good estimate". In the graph above, if h(B) is taken as 12 instead of 5, B's f becomes 15. After A is expanded, G with f = 13 is expanded before B (f = 3 + 12 = 15) and A* returns the path of cost 13, although the cheapest is 8. An h that exceeds the true cost can make search miss the cheapest path.
2.6Decisions under uncertainty
In real environments sensors are noisy and the full state is hidden. The agent keeps only a belief: a probability distribution over possible states. When a new observation arrives, the belief is updated with Bayes' rule; then the agent picks an action by looking at the utility of its outcomes.
P(H | O) = P(O | H) · P(H) / P(O); here H is a hypothesis (for example "there is an obstacle ahead") and O is the observation. The expected utility of an action is the utility of each outcome times its probability, summed: EU(a) = Σ P(s) · U(s, a). A rational agent picks the action with the largest EU.
The probability that there is an obstacle ahead of a robot is P(O) = 0.2. The front sensor raises an alarm 90% of the time when there is an obstacle and 10% of the time when there is none. The alarm sounds. (The values are illustrative.)
- Probability of an alarm. P(alarm) = 0.9 · 0.2 + 0.1 · 0.8 = 0.18 + 0.08 = 0.26.
- Update. P(O | alarm) = 0.18 / 0.26 ≈ 0.69. The belief rose from 0.20 to 0.69.
- Utilities. Braking costs 1 unit if there is no obstacle (an unnecessary stop) and 0 if there is one. Continuing costs 100 units if there is an obstacle (a crash) and 0 if there is none.
- Expected utilities. EU(brake) = −1 · 0.31 ≈ −0.31; EU(continue) = −100 · 0.69 ≈ −69.2. The robot brakes.
- A second alarm. If the sensor errors are independent, the second alarm multiplies the odds by the likelihood ratio (90/10 = 9): odds 2.25 × 9 = 20.25, so P(O) ≈ 0.95.
Braking is the right decision even at a small belief: continuing is better only when P(O) < 1/101 ≈ 0.01. Because a crash is so costly, the robot slows down even when it is not sure about the obstacle.
Three things connect here: an observation changes the belief, utility judges the outcomes, and a rational agent weighs both together. This framework extends to Bayesian networks, Markov decision processes and reinforcement learning.
Treating the obstacle as certain once the alarm sounds, or reasoning "the alarm is 90% accurate, so the obstacle is 90% likely". The 90% is P(alarm | obstacle), not P(obstacle | alarm); the difference between them is the prior. Here the prior was 0.2, so the result is 0.69; if obstacles were very rare, the same alarm would give much less confidence.
2.7How is the course taught?
2.7.1A typical workflow
A navigation app senses its location, represents the road network as a graph, searches routes with A*, picks the fastest one and guides the driver by voice. Nothing in this loop is "learned"; the system is still AI.
2.7.2Topics over the semester
- Intelligent agents and types of environments
- Uninformed search: BFS, DFS, uniform-cost search
- Heuristic search: greedy best-first and A*
- Local search: hill climbing, simulated annealing
- Adversarial search: minimax and alpha-beta pruning
- Constraint satisfaction problems and backtracking
- Propositional logic and inference by resolution
- First-order logic and knowledge representation
- Classical planning: STRIPS and PDDL
- Probability, Bayes' rule and Bayesian networks
- Decision theory and Markov decision processes
- Learning from examples and reinforcement learning
This is a typical semester; the order and coverage vary between universities.
2.7.3Skills you will gain
- formulating problems as state spaces
- implementing A* with heuristics
- logic programming in Prolog
- writing planning problems in PDDL
- building Bayesian networks with pgmpy
- comparing algorithms by complexity
2.7.4Try it yourself
The Try It: A Warehouse Robot Finds Its Way slide in the presentation lets you solve a typical problem of this course yourself: A warehouse robot must travel from cell R between the shelves to the item in cell H. Click a cell to add or remove a shelf; compare how many cells the two search methods examine.
2.8Are you ready for this course?
2.8.1Prerequisites
| Course | Why it is needed |
|---|---|
| Probability and Statistics | reasoning under uncertainty, Bayes' rule |
| Data Structures | stacks, queues, priority queues and graphs: the building blocks of search |
| Algorithms | graph search, shortest paths and complexity analysis |
| Discrete Mathematics | propositional logic, sets and proof techniques |
2.8.2Ask yourself
For every "no", the right-hand column shows where to start. If you can say "yes" to most of them, you are ready.
| Question | If not, start with |
|---|---|
| Can you trace BFS and DFS on a graph step by step on paper? | Graphs and queues from a data structures course |
| Can you explain a priority queue and big-O notation? | Complexity analysis from an algorithms course |
| Can you build a truth table with "and", "or" and "implies"? | Propositional logic from discrete mathematics |
| Can you explain conditional probability and Bayes' rule? | Probability and Statistics |
2.9Neighboring courses
2.9.1Where it overlaps
| Relation | Course | Shared ground |
|---|---|---|
| subfield | Machine Learning is a subfield of this course | an agent that learns from data; statistical generalization instead of search |
| subfield | Natural Language Processing and Text Mining is a subfield of this course | language understanding and generation |
| subfield | Fuzzy Logic and Fuzzy Systems is a subfield of this course | approximate reasoning |
| subfield | Evolutionary and Metaheuristic Optimization is a subfield of this course | heuristic search |
| subfield | Expert Systems and Knowledge Representation is a subfield of this course | symbolic AI, logic and rules |
| subfield | Multi-Agent Systems is a subfield of this course | the agent concept, collective decisions |
| builds on | This course builds on Probability and Statistics | reasoning under uncertainty, Bayes' rule |
| shares methods | Shares methods with Optimization | state-space search, constraint satisfaction |
2.9.2Where it differs
- Machine Learning: AI can find how to reach a goal by search or inference; ML learns the same behavior by generalizing from data.
- Expert Systems and Knowledge Representation: Expert systems are one approach within AI (rules and logic); AI also covers search, probability and learning.
- Optimization: Optimization solves a problem already stated mathematically; AI starts by modeling it as agent, environment and goal.
- Multi-Agent Systems: AI focuses on the decisions of a single agent; multi-agent systems study agents that affect one another.
2.10In practice
2.10.1Applications
| Area | What is done |
|---|---|
| Games | Chess and Go engines, computer opponents in games. |
| Route planning | Navigation, logistics, paths of warehouse robots. |
| Scheduling | Class timetables, flight crews and shift plans. |
| Virtual assistants | Systems that understand speech and turn it into tasks. |
| Autonomous vehicles | Where perception, prediction and planning meet. |
| Decision support | Diagnosis suggestions in medicine, fault diagnosis in engineering. |
2.10.2Risks and ethics
| Risk | Explanation |
|---|---|
| The wrong performance measure | An agent maximizes its measure literally: a route planner that only minimizes travel time can push traffic onto side streets past schools. |
| Search that does not scale | State spaces grow exponentially; a search that takes seconds on a toy problem runs out of memory and time at real size. |
| An incomplete knowledge base | A system that treats whatever is missing from its rules as false draws confident but wrong conclusions from one forgotten rule. |
| Responsibility for autonomy | When an autonomous car or weapon system decides on its own, it becomes unclear who answers for its mistakes. |
These issues are discussed in depth in Explainable AI and AI Ethics.
2.10.3Tools and datasets
Tools: Python, Prolog, PDDL planners, Google OR-Tools, Gymnasium, pgmpy (Bayesian networks).
Classic example problems: 8-puzzle, n-queens, Sudoku, Wumpus world, Traveling salesman, Chess and Go.
An AI course usually gives a problem definition instead of a dataset: once states, actions and the goal are known, the solution is found by search.
2.11Common misconceptions
AI and machine learning are the same thing.
ML is a subfield of AI. Search, planning and logic are AI even without learning.
AI aims to think like humans.
The course mostly aims at acting rationally; imitating humans is only one approach.
Chess engines learn by playing.
Classic engines like Deep Blue use search and a hand-written evaluation; learning is not required.
Chatbots are all of AI.
Large language models come from NLP and generative models; AI is a much broader field.
2.12Summary
- Artificial intelligence studies agents that perceive an environment and choose actions; an agent is described by PEAS: performance measure, environment, actuators, sensors.
- A rational agent chooses the action that maximizes the expected value of its performance measure given what it knows; if the measure is chosen wrongly, the agent does the wrong thing well.
- In fully observable, deterministic environments a problem is set up as a state space; BFS finds the path with the fewest actions, uniform-cost search the cheapest, and A* narrows the search with a heuristic function.
- If the heuristic never exceeds the true cost (admissible), A* returns the cheapest path; if it does, the returned path may not be the cheapest.
- Under uncertainty an agent updates its belief with Bayes' rule and picks the action with the highest expected utility; the prior and the cost of actions matter as much as the observation.
2.13Test Yourself
Write the PEAS description of a garden-watering robot and describe its environment on four properties (observable, deterministic, discrete, changing while the agent thinks).
Answer
Performance measure: time the soil moisture stays in the desired range, water used. Actuators: valve, wheels. Sensors: moisture and rain sensors, position. Environment: because it depends on rain and sun it is partially observable, random, continuous and changes while the agent thinks.
A reflex agent ("if dirty, suck; otherwise move to the other square") starts in B of a two-square room; B is clean and A is dirty. Score the number of clean squares at each of four steps. What is the total?
Answer
Step 1: B is clean, moves to A; clean squares 1 (B). Step 2: A is dirty, sucks; clean 2. Step 3: A is clean, moves to B; clean 2. Step 4: moves to A; clean 2. Total 1 + 2 + 2 + 2 = 7.
In a tree where every state has 3 actions, the goal is at depth 4. How many nodes does BFS generate in the worst case?
Answer
The number of nodes at depths 0 to 4 is 1, 3, 9, 27, 81. Total 1 + 3 + 9 + 27 + 81 = 121. This grows exponentially with depth: at depth 8 it is 9841, which is why heuristic search is needed.
In the 8-puzzle the start state is "2 8 3 / 1 6 4 / 7 _ 5" and the goal is "1 2 3 / 8 _ 4 / 7 6 5". Find the number of misplaced tiles and the Manhattan sum.
Answer
The misplaced tiles are 2, 8, 1 and 6: count 4. Manhattan: 2 is one column away (1), 8 is two squares away (2), 1 is one square away (1), 6 is one square away (1); 3, 4, 5 and 7 are in place. Total 1 + 2 + 1 + 1 = 5. The Manhattan sum is larger than the misplaced count (5 > 4) and does not exceed the true cost; both are admissible, but Manhattan is more informative.
For a burglar alarm, P(burglar) = 0.01; the alarm sounds with probability 0.95 if there is a burglar and 0.05 if there is none. What is the probability of a burglary when the alarm sounds? Compare with your intuition.
Answer
P(alarm) = 0.95 · 0.01 + 0.05 · 0.99 = 0.0095 + 0.0495 = 0.059. P(burglar | alarm) = 0.0095 / 0.059 ≈ 0.16. Although the alarm is 95% sensitive, the event is so rare that there is a burglar only about one time in six.
The probability of rain is 0.3. Taking an umbrella has utility 0 in rain and −1 without rain (the nuisance of carrying it). Not taking it has utility −10 in rain and 0 without. Which is chosen? Above which probability of rain is taking the umbrella worthwhile?
Answer
EU(take) = −1 · 0.7 = −0.7; EU(leave) = −10 · 0.3 = −3. The umbrella is taken. They are equal when 10p = 1 − p, that is p = 1/11 ≈ 0.09; above that probability, taking it is better.
2.14After this course
AI is the roof of this guide: machine learning, natural language processing, fuzzy logic, evolutionary optimization, expert systems and multi-agent systems are its branches. To decide which branch interests you, a good start is to see this course's search, logic and uncertainty topics first.
Courses that build on or extend this one: Machine Learning, Natural Language Processing and Text Mining, Fuzzy Logic and Fuzzy Systems, Evolutionary and Metaheuristic Optimization, Expert Systems and Knowledge Representation, Multi-Agent Systems.
Related careers: AI engineer, Researcher, Game AI developer, Robotics software engineer, Decision support specialist.
2.15Further reading
- S. Russell and P. Norvig, Artificial Intelligence: A Modern Approach (4th ed., 2020): presents the agent framework, search and probabilistic reasoning at the level closest to a course; the agent and PEAS vocabulary of these notes comes from it.
- D. Poole and A. Mackworth, Artificial Intelligence: Foundations of Computational Agents (3rd ed., 2023): covers the same topics from an agent point of view with many worked examples.
- N. Nilsson, The Quest for Artificial Intelligence (2010): a readable account of the history of the field and where its ideas came from.
2.16References
- Russell and Norvig, Artificial Intelligence: A Modern Approach, 4th ed., Pearson, 2020.
- Poole and Mackworth, Artificial Intelligence: Foundations of Computational Agents, 3rd ed., Cambridge University Press, 2023.
- Nilsson, The Quest for Artificial Intelligence, Cambridge University Press, 2010 (history of the field).
- Turing, "Computing Machinery and Intelligence", Mind 59(236), 1950.
Related pages: Slides · Slides (PDF) · Course page