CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
Lecture 1
An Introduction to Artificial Intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
Content
▪ What is intelligence?
▪ Artificial intelligence in daily life
▪ What is artificial intelligence?
▪ History of Artificial intelligence.
▪ Foundation of Artificial intelligence.
Artificial intelligence in daily life
Digital assistants
•Cortana (Microsoft)
Siri (Apple)
Alexa (Amazon)
https://www.youtube.com/watch?v=whMS3QbYAP0
Artificial intelligence in daily life
Search engines
▪
▪
▪
▪
▪
Google
Opera
Firefox
Safari
Internet
explorer
Artificial intelligence in daily life
Social media
▪ Facebook
▪ Instagram
▪ YouTube
▪ TikTok
Artificial intelligence in daily life
▪ Google translate
▪ QuillBot
▪ Grammarly
▪ ChatGPT
▪ Deepseek
Artificial intelligence in daily life
What is intelligence?
▪ Intelligence is the ability to learn, solve problems,
and use knowledge to adapt to new situations.
What is Artificial intelligence?
▪ Some definitions of AI, organized into four categories (Rusell and Norvig):
Thinking humanly
Thinking rationally
“Cognitive modeling approach”
“Laws of thought approach using logic”
Acting humanly
Acting rationally
“Turing test ”
“The rational agent approach”
• Rationally= doing the right thing
• Acting= behavior
What is Artificial intelligence?
▪ Some definitions of AI, organized into four categories:
Systems that act like humans
Systems that act rationally
Turing test approach
The rational agent approach
Systems that think like humans
Systems that think rationally
Cognitive modeling approach
Laws of Thought approach using logic
What is Artificial intelligence?
▪ Some definitions of AI, organized into four categories:
Systems that act like humans
Systems that act rationally
The art of creating machines that
perform functions that require human
intelligence. (Kurzweil, 1990)
Systems that think like humans Systems that think rationally
Approach 1: Acting Humanly
•Turing test (Imitation game):
▪It is an ultimate test for acting humanly.
▪ It is a test for machine intelligence.
▪Computer and human both interrogated
by a judge.
▪ The computer passes the test if the
judge can’t tell the difference.
Alan Turing, 1950: was an English
mathematician, wartime code-breaker
and pioneer of computer science.
Systems that act like humans (Turing test)
The system (machine) would need to possess the following
capabilities:
▪ Natural language processing to enable it to communicate
successfully in English.
▪ Knowledge representation to store what it knows or hears.
▪ Automated reasoning to use the stored information to answer
questions and draw new conclusions.
▪ Machine learning to adapt to new circumstances and to detect
and extrapolate patterns.
Notable AI machines and Their Attempts at the
Turing Test
• ELIZA (1966)
• PARRY (1972)
• ALICE
• Eugene Goostman
Interviewing Sophia:
https://www.youtube.com/watch?v=0HoSwHNUOHg
BabyX
virtual
https://www.youtube.com/watch?v=fNWjKtVWToc
Why do we want an intelligent system to act like human?
•Because for many tasks, humans are still the gold standard.
•Humans are needed in high-skilled innovation and critical
decision-making jobs, as well as in fields that require
emotional intelligence.
Total Turing test
• Turing test is extended to include physical aspects of human
behavior, and hence the computer capabilities will be
extended to include:
▪ Computer vision to perceive objects.
▪ Robotics to manipulate objects and move.
Computer vision
• It is a field of computer science that allows computers to see and
understand the contents of digital images, such as photographs or
videos.
Uses of computer vision
Is this a cat?
What is there in the
image and where?
Which pixels belong to
which object?
Uses of computer vision
•Object detection: find where the objects are in the image. and
draw a bounding box around it.
•Semantic Segmentation: what pixels belong to the object in the
image? each pixel is assigned to an object
•Classification/Recognition: Given an image with an object, find
out what that object is. In other words, classify it in a class from
a set of predefined categories.
Robotics
▪ Robotics is a branch of engineering and computer science that
involves the conception, design, manufacture, and operation of
robots.
Natural language processing (NLP)
NLP is a machine-learning technology that gives computers
the ability to interpret, manipulate, and comprehend human
language.
Uses of Natural Language Processing
▪ Summarization: NLP can also be used to summarize text
▪ Speech to Text Conversion
▪ Sentiment Analysis: NLP is used to analyze the positive and
negative nature of the sentence.
▪ Text classification
▪ Spell checking
▪ Grammar checking: ex. Grammarly, Quillbot
▪ Question answer: ex. ChatGPT, Gemini, DeepSeek
▪ Voice Assistants: ex. Siri in iPhone, Amazon Alexa
Approach 2 : thinking humanly
“The cognitive modeling approach”
• To say that a given program thinks like a human, we need to get
inside the workings of the human mind:
1. Introspection—trying to catch our own thoughts
2. psychological experiments—observing a person in action
3. brain imaging—observing the brain in action.
• Once we have a sufficiently precise theory of the mind, it becomes
possible to express the theory as a computer program
What is Artificial intelligence?
▪ Some definitions of AI, organized into four categories:
Systems that act like humans
Systems that act rationally
The art of creating machines that
perform functions that require human
intelligence.
Systems that think like humans
The effort to make computers think . .
. Machines with mind.
Systems that think rationally
Cognitive science
▪ Cognitive Science is the study of the human mind and brain,
focusing on how the mind represents and manipulates knowledge.
Approach 3: Thinking rationally
“laws of thought” approach
Systems that act like humans
Systems that act rationally
The art of creating machines
that perform functions that
require human intelligence.
Systems that think like humans
Systems that think rationally
The effort to make computers The study of the computations that make
think . . . Machines with mind.
it possible to perceive, reason, and act.
Approach 3: thinking rationally
“laws of thought” approach
•Systems yielded correct conclusions when given correct
premises—for example, “Socrates is a man; all men are
mortal; therefore, Socrates is mortal.”
•Obstacles
• It is not easy to express informal knowledge by logical notation, particularly
when the knowledge is less than 100% certain.
• Second, there is a big difference between solving a problem “in principle” and
solving it in practice. Even problems with just a few hundred facts can exhaust
the computational resources of any computer unless it has some guidance.
Approach 4: Thinking rationally
“The rational agent approach”
Systems that act like humans
Systems that act rationally
The art of creating machines that It is the study of intelligent agent
perform functions that require design.
human intelligence.
Systems that think like humans
Systems that think rationally
The effort to make computers think The study of the computations
. . . Machines with mind.
that make it possible to perceive,
reason, and act.
Intelligence
11:00 PM · Mar 5, 2024
·
422
Views
Settings
. #HistoryofAI #TechEvolution
Foundations of Artificial Intelligence
▪ Philosophy
✓ Can the formal rules be used to
draw conclusions?
✓ How does knowledge lead to an
action?
▪ Mathematics
✓ What are the formal rules to
draw conclusions?
▪ Neuroscience
✓
how does the brain process
information?
▪ Psychology
✓
How do humans and animals
think and act?
▪ Economics
✓ How should we
maximize profit?
do
to
▪ Computer engineering
✓
How can we build an efficient
computer?
▪ Linguistics
✓ how does
thought?
language
relate
to
Assignment 1
▪ What is intelligence?
▪ What is artificial intelligence using four different categories?
▪ Define the following concepts: Turing test- total Turing test- computer
vision- robotics- natural processing language (NLP)- cognitive scienceclassification – object segmentation – object detection
▪ State some uses of the computer vision field.
▪ State some uses of natural processing language.
▪ What can AI do today?
▪ Describe the foundation of Artificial intelligence.
▪ Why do we want an intelligent system to act like a human?
▪ Describe the capabilities that need to be found in the computers for the
Turing test.
Reference resources
• Russell, S. J., & Norvig, P. (2016). Artificial intelligence: a modern
approach. Pearson.
• Ertel, W. (2024). Introduction to artificial intelligence. Springer Nature.
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
Lecture 2
Intelligent agents
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
Lecture Content
Recap
What is an intelligent agent? Ex. Vacuum cleaner agent
Agents and environments
Rationality
Specifying task environment: PEAS (Performance measure,
Environment, Actuators, Sensors)
Environment properties
Agent classification (types)
Recap
Some definitions of AI, organized into four categories (Rusell and Norvig):
Thinking humanly
Thinking rationally
“Cognitive modeling approach”
“Laws of thought approach using logic”
Acting humanly
“Turing test ”
• Rationally= doing the right thing
• Acting= behavior
Acting rationally
“The rational agent approach”
What is an intelligent agent?
An intelligent agent is an entity that perceives its environment
through sensors and acts on that environment through
actuators. (Rusell and Norvig)
Intelligent agent
Agents can be biological (people or animals,
for example), robotic, or computational
(software).
Human agent :
Sensors = eyes, ears
Actuators (effectors) = hands, legs, mouth.
Robotic agent:
Sensors = cameras, sonar, lasers.
Effectors = grippers, manipulators, motors.
Gripper
Intelligent agent properties
1. Autonomy
2. Adaption
3. Cooperation
1. Autonomy
It is the ability of an agent to act and make
decisions independently of the user.
Example
An intelligent buying agent that buys goods on
behalf of a user’s needs and makes decisions
about what items to purchase without
checking back with the user.
Adaption
It is the ability of an agent to learn and
adapt when presented with new situations.
Example:
Agents can learn from a user by
observing actions or by being given
instructions.
Agents can also learn from other agents
in multiagent systems.
Cooperation
In multiagent systems, the gent can cooperate with each other.
It is a form of social interaction between agents.
Example:
A buying agent may negotiate with a selling agent to make
purchases.
Agent function
Agent function describes the agent behavior that maps any
given percept sequence to an action.
It is an abstract mathematical description.
Example: Vacuum cleaner.
A vacuum-cleaner world with just two locations
The agent function of Vacuum cleaner agent
Tabulation of a simple agent function
for the vacuum cleaner world
Percept sequence
[A, clean]
Action
Right
[A, dirty]
[B, clean]
[B, dirty]
Suck
Left
Suck
[A, clean], [B, clean]
Right
[A, clean], [B, dirty]
Suck
[A, Clean], [A, Clean], [A, Clean] Right
…
…
Vacuum cleaner world with just
two locations
Agent program
Agent program is an internal implementation of the agent
function.
Example: The agent program for a simple reflex agent in the
two-state vacuum environment.
function REFLEX-VACUUM-AGENT( [location, status] ) returns an action
if status = Dirty then return Suck
else if location = A then return Right
else if location = B then return Left
Agent architecture
Agent architecture is the physical components of agent
(sensors and actuators) in which the agent program will run.
Agent = Architecture + Program
The program has to be appropriate for the architecture.
Ex: If the program will recommend actions like Walk, the
architecture had better to have legs.
Rational agent
Rationality means doing the right thing
A rational agent is an agent that does the right thing.
A performance measure evaluates how successful the agent is.
There is no fixed performance measure for all tasks and agents
a designer will devise one appropriate to the circumstances.
Ex: Performance measure for a vacuum cleaner agent:
Awarding one point for each clean square
Penalty for electricity consumed and noise generated.
Rational agent
What is rational at any given time depends on four things:
The performance measures that define the success
criteria (goals).
The agent’s prior knowledge of the environment.
percept sequence up to date.
The possible actions of the agent.
Rational agent
Performance measure awards one point for each clean square.
The environment is known a priori Two locations A, B
The dirt distribution and agent’s initial location are not known.
Actions: Suck, Left, Right.
The agent perceives its location and whether that location
contains dirt.
Omniscient agent
An omniscient agent knows the actual outcome of
its actions and can act accordingly, but omniscience
is impossible in reality.
In comparison, a rational agent behaves according
to its percepts and knowledge and attempts to
maximize the expected performance.
Example: if I look both ways before crossing the
street and then as I cross, I am hit by a car. I can
hardly be accused of lacking rationality.
Omniscient = have all knowledge
Omniscient ≠ rational
Task environment
Before we design an intelligent agent, we must specify its
task environment.
PEAS:
Performance measure
Environment
Actuators
Sensors
Task environment
Describe the task environment (PEAS) for the following:
Pacman
Autonomous taxi driver
Chess game
Medical diagnosis system
Part-picking robot
Interactive English tutor
Backgammon
Pacman game
Performance measure: -1
per step, +10 food, +500
win, -500 die,
+200 hit
scared ghost
Environment:
Pacman
dynamics
barriers,
ghosts, Pacman, white dots
Actuators:
down.
Sensors: Entire state is
visible full observable
board.
Left, right, up
Task environment for autonomous taxi driver
Performance measure: safe, fast, comfortable, profit, fines
Environment: roads, traffic, pedestrians, customers, other
vehicles, traffic officers
Actuators: steering, accelerator, brake, signal, horn
Sensors: cameras, Infrared or sonar sensors to detect
distances and obstacles, speedometer, GPS, odometer,
accelerometer, engine sensors, Keyboard or Microphone for
passengers to request destination.
Task environment for chess game
Agent type
Performance
measure
Chess game 1 point Win
-1 point lose
0 point draw
Environment Sensor
Actuator
Chessboard, See board
opponent
position as
8×8 matrix
Move piece to
target position
Game idea:
https://www.youtube.com/watch?v=ctDQCpSSzow
Task environment for medical diagnosis system
Agent
type
Medical
diagnosis
system
Performance
measure
Healthy
patient,
reduced costs
Environmen Sensor
t
Patient,
Keyboard entry
hospital,
of symptoms,
Staff,
findings,
patient’s
answers
Actuator
Display of
questions, tests,
diagnoses,
treatments,
referrals
Task environment for Part-picking robot
Agent type Performance
Environment
measure
Part-picking Percentage of
Conveyor belt
robot
parts in correct bins with parts, bins
Sensor
Actuator
Camera, joint Jointed arm and
angle
hand
sensors
Task environment for Interactive English tutor
Agent type
Performanc Environment
e measure
Interactive
Student’s
Set of
English tutor score
students
on test
Sensor
Actuator
Keyboard entry,
camera,
microphone,
speaker
Display of
exercises,
suggestions,
corrections
Backgammon
Performance measure: The first
player to bear off all 15 pieces
wins the game
Environment:
Game
board,
opponent
Actuator: roll dice, move pieces
Sensors: the full board
Game idea:
https://www.youtube.com/watch?v=AlkR73-U_00
Properties of task environment
Single agent vs. multiagent
Fully observable vs. partially observable
Competitive vs. Cooperative
Deterministic vs. Stochastic
Episodic vs. Sequential
Static vs. dynamic
Discrete vs. Continuous
Single-agent vs Multi-agent
Single-agent environment contains only one agent.
Ex: Crossword is a single agent,
Ex: a single person in a maze is a single-agent system.
A multi-agent environment contains more than one agent.
Ex: chess and football are multi-agent environments.
Fully Observable vs Partially Observable
The environment is fully observable when an agent sensor can
access the complete state of the environment.
No need to keep track of the surroundings’ history.
An environment might be partially observable due to noisy and
inaccurate sensors or since parts of the environment are
inaccessible.
An environment is called unobservable when the agent has no
sensors in its environment.
•Examples:
• Chess – the board is fully observable and opponent’s moves.
• Taxi driver – the environment is partially observable as what’s
around the corner is not known.
Example
Crossword
Fully
Poker
Backgammon Taxi
driver
Partially Partially
Partially
Part-picking
robot
Partially
Image
analysis
Fully
Deterministic vs Stochastic
Deterministic environment: if the next state of the environment is
completely determined by the current state and the action executed
by the agent.
The stochastic environment is random in nature which is not unique
and cannot be completely determined by the agent.
Examples:
Chess – there would be only a few possible moves for a chess
piece at the current state and these moves can be determined.
Vacuum environment is deterministic
Taxi driver: the actions of a taxi driver are not unique, it varies
time to time (stochastic).
Stochastic is connected to randomness events
Competitive vs Collaborative
An agent is in competitive environment when it competes
against another agent to optimize the output.
The game of chess is competitive as the agents compete
with each other to win the game which is the output.
An agent is in a collaborative environment when multiple
agents cooperate to produce the desired output.
multiple self-driving cars cooperate with each other
to avoid collisions and reach their destination which
is the output desired.
Players of a single football team.
Dynamic vs Static
A dynamic environment is constantly changing while the
agent is deliberating.
Ex: taxi driving is dynamic
An idle environment with no change in its state is called a
static environment.
EX: An empty house is static as there’s no change in
the surroundings when an agent enters.
EX: Crossword puzzles are static
Semidynamic: If the environment itself does not change with
the passage of time but the agent's performance score does.
Discrete vs Continuous
If an environment consists of a finite number of actions that can
be deliberated in the environment to obtain the output, it is a
discrete environment.
Chess is discrete as it has only a finite number of moves.
The number of moves might vary with every game, but
still, it’s finite.
The environment in which the actions are performed cannot be
numbered i.e. is said to be continuous.
Self-driving cars are continuous environments as their
actions are driving, parking, etc. cannot be numbered.
Episodic vs Sequential
In an episodic environment, the agent’s actions are divided into atomic
episodes. There is no dependency between current and previous episodes. In
each episode, an agent receives input from the environment and performs the
corresponding action.
Ex: Pick and Place robot, which is used to detect defective parts from the
conveyor belts. Every time, the robot (agent) will decide on the current part i.e.
there is no dependency between current and previous decisions.
In a sequential environment, the previous decisions can affect all future
decisions. The agent’s next action depends on what action he has taken
previously and what action he is supposed to take in the future.
Ex: Chess- the previous move can affect all the following moves.
Taxi driver
Known vs Unknown
In a known environment, the output for all probable
actions is given.
In the case of an unknown environment, for an agent to
make a decision, it has to gain knowledge about how
the environment works.
It isn’t a property of the environment, but it is the
property of agent’s state of the knowledge.
Environment types
The simplest environment is fully observable,
deterministic, episodic, static, discrete, and singleagent.
Most real situations are Partially observable,
stochastic, sequential, dynamic, continuous, and
multi-agent.
Environment properties
Environment
Observable
Deterministic
Episodic
Static
Discrete
Agents
Crossword puzzle
Fully
deterministic
Sequential
static
Discrete
single
Chess with a clock
Fully
deterministic
Sequential
semi
Discrete
Multi
Poker
Partial
Stochastic
Sequential
Static
Discrete
Multi
Backgammon
Fully
Stochastic
Sequential
Static
Discrete
Multi
Taxi driving
Partial
Stochastic
Sequential
Dynamic Continuous Multi
Medical diagnosis
Partial
Stochastic
Sequential
Dynamic Continuous Single
Image analysis
Fully
Deterministic
Episodic
Semi
Discrete
Robot part picking
Fully
Deterministic
Episodic
Semi
Continuous Single
Refinery controller
Partial
stochastic
sequential
dynamic
continuous
Interactive English tutor
Partial
Stochastic
Sequential
Dynamic Discrete
Single
single
Multi
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
Simple reflex agent
It select actions based on the current percept, ignoring the rest of
the percept history.
Ex: vacuum cleaner is a simple reflex agent, why?
Since its decision is based only on the current location and
whether it contains dirt.
function REFLEX-VACUUM-AGENT( [location, status] ) returns an action
if status = Dirty then return Suck
else if location = A then return Right
Condition-action rule
else if location = B then return Left
When the current square is dirty, the action does not depend on
the location.
Simple reflex agents
Ex: The driver of the automated taxi
if car-in-front-is-braking then initiate-braking.
Simple reflex agents
Drawback:
Work only if the environment is fully observable
A little bit of unobservability can cause serious trouble.
Drawback of simple reflex agent
For example, the braking rule given earlier assumes that the
condition car-in-front-is-braking can be determined from the
current percept—a single frame of video. This works if the car
in front has a centrally mounted brake light.
Unfortunately, older models have different configurations of
taillights, brake lights, turn-signal lights, and it is not always
possible to tell from a single image whether the car is braking.
A simple reflex agent driving behind such a car would either
brake continuously and unnecessarily, or, worse, never brake
at all.
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
Model-based reflex agent
It can handle partial observable environments.
The agent has a memory to maintain the percept history.
For the braking problem, the internal state is not too extensive—
just the previous frame from the camera, allowing the agent to
detect when two red lights at the edge of the vehicle go on or
off.
Model-based reflex agent
It requires two kinds of knowledge to be encoded in the
agent program (Model of the world).
1. How the world evolves independently of the agent.
For example, that an overtaking car generally will be closer behind
than it was a moment ago.
2. How the agent’s own actions affect the world.
For example, that when the agent turns the steering wheel
clockwise, the car turns to the right
Model-based reflex agents
Model-based reflex agents
Drawback of model-based agent
Percepts alone are insufficient to decide what to do.
For example, at a road junction, the taxi can turn left, turn right,
or go straight on. The correct decision depends on where the
taxi is trying to get to.
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
Goal-based agents
It keeps track of the world state in addition to a set of goals it is
trying to achieve, and chooses an action that will lead to the
achievement of its goals.
It works towards goals.
Example:
Taxi driver destination.
Goal-based agents
Drawback of goal-based agent
Goals alone are not enough to generate high-quality
behavior in most environments.
For example, many action sequences will get the taxi to its
destination, but some are quicker, safer, more reliable, or
cheaper than others.
Utility-based agents
several possible actions can be taken in a given situation.
Utility–based agent selects the action that maximizes their
reward.
Utility function maps a state (or sequence of states into a
real number). The agent uses this number to weigh the
importance of the competing goals.
Ex: taxi driver may have many paths leading to the goal, but
some are safer, quicker, and cheaper.
Utility-based agents
Learning agent
Learning agents improve their behavior over time.
They can become more competent over time.
It tries to maximize their own expected ―happiness.‖
They can start with an initially empty knowledge base.
They can operate in initially unknown environments.
Learning agent
Determines the agent
performance
Suggests exploratory actions
that
will
lead
to
new
informative experiences
Responsible for
making improvements
Take percept and
decide an action
Assignment 2
Define intelligent agent, omniscient agent, rational agent, and
agent function.
Describe intelligent agent properties.
Describe the (PEAS) task environment for the following:
Autonomous taxi driver.
Chess
Medical diagnosis systems
Satellite imagery
Part-picking robot
Refinery controller
Interactive English tutor
Backgammon
Assignment 2
Differentiate between the following:
Human agent and robotic agent.
Fully observable and partially observable environments
Deterministic vs. Stochastic environments
Competitive vs collaborative environments
Single-agent vs multi-agent environments
Dynamic and static environments
Sequential and episodic environments
Known and unknown
Goal-based agent and utility-based agent
Describe the environment properties of the following: crossword
puzzle- chess-poker-taxi driver- robot part picking- interactive English
tutor- refinery controller.
Reference resources
Coppin, B. (2004). Artificial intelligence illuminated. Jones &
Bartlett Learning.
Russell, S. J., & Norvig, P. (2016). Artificial intelligence: a
modern approach. Pearson.
https://tutorialforbeginner.com/types-of-ai-agents
https://slideplayer.com/slide/14293658/
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
2/22/2025
Lecture 3
Solving problems by searching
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
2/22/2025
Lecture Content
Recap
Agent types: model-based agent, goal-based agent, utilitybased agent.
Problem-Solving Agents
Example Problems
Searching for Solutions
Uninformed Search Strategies
Informed (Heuristic) Search Strategies
Heuristic Functions
2/22/2025
Recap
Some definitions of AI, organized into four categories (Rusell and Norvig):
Thinking humanly
“Cognitive modeling approach”
Thinking rationally
Laws of thought approach using
logic”
Acting humanly
Acting rationally
“Turing test ”
“The rational agent approach”
• Rationally= doing the right thing
• Acting= behavior
2/22/2025
Recap
Autonomy
Adaption
Cooperation
2/22/2025
Agent
Sensors
?
Actuators
Environment
Fully observable vs. partially observable
Single agent vs. multiagent
Competitive vs. Cooperative
Deterministic vs. Stochastic
Episodic vs. Sequential
Static vs. dynamic
Discrete vs. Continuous
Agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
2/22/2025
Simple reflex agent
Agent
Sensors
What the world is like now
Condition-action rules
What action I
should do now
Effectors
Environment
It select actions based on the current
percept, ignoring the rest of the
percept history.
Ex: Vacuum cleaner
It works well in fully observable
environment.
Basic components:
1. Sensors: gathers information about
what the world is like now (status).
2. Condition-action rules: the agent
matches the status with its.
3. Actuators: executes the selected
action.
Simple reflex agent
Automatic Doors: Open when sensing
movement nearby. The door react to
immediate presence detection, requiring
no memory or context.
Smoke Detectors: Trigger an alarm upon
detecting smoke particles in the air. Their
responses are immediate and based solely
on current air quality.
Agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
2/22/2025
Model-based reflex agent
It can handle
environments.
dynamic
and
partial
observable
The agent keeps track of the part of the world it can’t see
now.
The agent has a memory to maintain the percept history.
For the braking problem,— from the previous frame of
the camera, the agent can detect when two red lights at
the edge of the vehicle go on or off.
2/22/2025
Model-based reflex agent
Internal state
State
How the world evolves
What my actions do
Condition-action rules
Agent
2/22/2025
Sensors
What the world
is like now
What action I
should do now
Effectors
Environment
The agent interprets the
current state with reference
to
previous
percepts,
leading to more informed
decisions,
and
even
predicting
the
impact of its actions.
Model-based reflex agent
It requires two kinds of knowledge to be encoded in the agent
program (Model of the world).
1. How the world evolves independently of the agent.
For example, an overtaking car generally will be closer behind than
it was a moment ago.
2. How the agent’s own actions affect the world.
For example, when the agent turns the steering wheel clockwise,
the car turns to the right.
2/22/2025
Model-based reflex agent
Autonomous vehicles: use an internal
model of the environment to navigate,
considering past data like road
conditions, nearby vehicles, and traffic
signals to make real-time driving
decisions.
Robotic Vacuum Cleaners: Advanced
models map the area to remember
cleaned spots and avoid obstacles,
adjusting paths based on past data for
more efficient cleaning.
2/22/2025
Model-based reflex agents
2/22/2025
Simple reflex agent vs. model-based agent
2/22/2025
Simple reflex agent vs. model-based reflex agent
Aspect
Simple Reflex Agent
Decision Basis Current percept
Memory
Environment
Example
response
Complexity
2/22/2025
Model-Based Reflex Agent
Current percept+ internal state
None
Retains past states to inform decisions
Effective in fully observable, Better for dynamic or partially observable
static environments
environments
A robot vacuum updating its map to avoid
Smoke detector
obstacles
Faster response
Slower response
Low computational
resources
It requires resources to build, update, and
utilize the internal model, leading to
increased computational complexity.
Drawback of model-based agent
Percepts alone are insufficient to decide what to do.
For example, at a road junction, the taxi can turn left, turn right,
or go straight on. The correct decision depends on where the
taxi is trying to get to. (goal)
2/22/2025
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
2/22/2025
Goal-based agents
It keeps track of the world state in addition to a set of goals it is
trying to achieve, and chooses an action that will lead to the
achievement of its goals.
It works towards goals.
Example:
- Taxi driver destination (airport).
2/22/2025
Goal-based agents
Internal state
State
What the world
is like now
What my actions do
What it will be like
if I do action A
Goals
Agent
2/22/2025
What action I
should do now
Effectors
Environment
How the world evolves
Sensors
Drawback of goal-based agent
Goals alone are not enough to
generate high-quality behavior
in most environments.
For example, many action
sequences will get the taxi to
its destination, but some are
quicker, safer, more reliable, or
cheaper than others.
2/22/2025
Model-based agent vs. goal-based agent
2/22/2025
Aspect
Decision
Basis
Model-Based Agents
Goal-Based Agents
React to changes using Act to achieve defined
condition-action rules
goals
Requires planning and
Memory
Simple rule-based reactions
evaluating future actions
Suitable for environments Best for tasks needing
Environmental
requiring
context-aware long-term
goal
Suitability
reactions
achievement
A smart sprinkler system A GPS system planning
Example
adjusting watering schedules the optimal route to a
based on soil moisture
destination
2/22/2025
Basic agent types
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
2/22/2025
Utility-based agents
Several possible actions can be taken in a given situation.
Utility–based agent selects the action that maximizes their reward.
Utility function maps a state (or sequence of states) into a real
number. The agent uses this number to weigh the importance of
the competing goals.
Ex: taxi driver may have many paths leading to the goal, but some
are safer, quicker, and cheaper.
2/22/2025
Utility-based agents
2/22/2025
Problem-solving agent
It is a kind of goal-based agent.
The agent adopts a goal and aims at achieving it.
2/22/2025
Problem formulation
Problem formulation is the process of deciding
what actions and states to consider, given a goal.
The process of looking for action/action sequence
that reaches the goal is called search.
2/22/2025
Problem formulation
A problem can be defined by five components:
1
2
3
4
5
Initial
state
Actions
Transition
model
Goal test
Path cost
possible
determines
function that
actions that defines the new whether a
assigns a
agent
starts in an agent can state resulting given state is a numeric cost
goal state
from doing an
to each path
take for a
action in the
given state
current state
2/22/2025
Example problems
2/22/2025
Example 1: Romania Vacation
On vacation in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest.
2/22/2025
State Space/Transition model defined as graph
2/22/2025
Example 1: Romania Vacation
Initial state: Arad
Actions: Drive from one city to another.
Transition model and states: If you go from city A to city B,
you end up in city B.
Goal state: Bucharest
Path cost: Sum of edge costs.
2/22/2025
Example: Romania map
2/22/2025
Example 1: Romania map
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest.
Formulate goal:
be in Bucharest
Formulate problem:
States: various cities
Actions: drive between cities
Find solution:
Sequence of cities, e.g., Arad Sibiu Fagaras Bucharest
Optimal solution is a set of sequence actions/states that has
the best cost among all solutions.
2/22/2025
Example 2: vacuum cleaner
States: determined by both the agent location and the dirt locations.
Initial state: Any state can be designed as the initial state.
Actions: Left, Right, Suck.
Transition model: (A, dirty) Suck
Goal test: checks if all squares are clean.
Path cost: Each step costs 1.
The agent is in one of two locations, each
of which might or might not contain dirt.
2 × 𝟐𝟐 = 8 states
2/22/2025
Example 2: vacuum cleaner
State space graph of vacuum cleaner
Goal state
2/22/2025
Example 3: 8 puzzle
States: each state denotes the location of eight
tiles and the blank in one of the nine squares.
Number of states approximately is n! permutation of the 9 tiles.
7
5
8
2
3
4
6
1
Start state
Initial State: Any state can an initial state.
Actions: Move blank left, right, up, down
Transition model: Given a state and action, this
returns the resulting new state
Goal state: arrange tiles as empty and 1:8 in order.
Path cost: 1 per tile move.
2/22/2025
1 2
3 4 5
6 7 8
Goal state
Example 3: 8 puzzle
2/22/2025
Example 3: 8 puzzle
State space graph
2/22/2025
Solving Search Problem
Given a search problem definition
Initial state
Actions
Transition model
Goal state
Path cost
Optimal solution is a set of
actions/states sequence that has
the best cost among all solutions.
2/22/2025
How do the optimal solution is found
(sequence of actions/states)?
Construct a search tree for the
state space graph!
Issue: Transition Model is Not a Tree! It can have Redundant Paths.
Cycles
Return to the same
state
Goal states
2/22/2025
Issue: Transition Model is Not a Tree! It can have Redundant Paths.
Non-cycle redundant paths
Path 1
Goal states
2/22/2025
Path 2
Graph
A graph is a set of nodes and links (edges) that
connect them.
A path cost function that assigns a numeric cost to
each path.
cost
Undirected graph
2/22/2025
Undirected graph
Directed graph (digraph)
Search tree
Search tree is a tree representation of a search
problem. The root node corresponds to the initial
state found at the top of the search tree.
Root node (initial state)
• The children of node B are D, E
• The parent of node F is C
A
B
D
2/22/2025
C
E
F
G
Search tree
If the node has at
least one child
Siblings: 5,9
Tree height
Parent of 5, 9 is 7
2/22/2025
Search space
A search space is a collection of probable solutions that a
system could have.
A solution is an action sequence that goes from the initial
state to a goal state.
State space: set all states in the space (A, B, C, D, E, F, G).
Root node (initial state)
A
B
D
2/22/2025
C
E
F
G
Goal node
Redundant path
They exist whenever there is more than one way to
get from one state to another.
ACG
ABEG
A
B
D
C
E
G
2/22/2025
F
G
Tree search approaches
There are two main approaches to searching a
search tree: data-driven search and goal-driven
search.
Tree search algorithms
Data-driven search
2/22/2025
Goal-driven search
Tree search approaches
Data-driven search starts from an initial state and uses
actions that move forward until a goal is reached.
2/22/2025
Tree search approaches
Goal-driven search starts at the goal and works back
toward the initial state, by seeing what moves could have
led to the goal state.
2/22/2025
State graph of Romania
2/22/2025
Search tree for Romania
The root node of the tree corresponds to the initial state,
(Arad).
The first step is to test whether this is a goal state.
Arad
2/22/2025
State graph of Romania
2/22/2025
Search tree for Romania
(a) After expanding Arad
Arad
Sibiu
2/22/2025
Timisoara
Zerind
State graph of Romania
2/22/2025
Search tree for Romania
(c) After expanding Sibiu
Arad
Sibiu
Arad
Fagaras
Timisoara
Oradea
Zerind
Rimnicu
Vilcea
Loopy path: in which the path contains a repeated state in the search tree.
Ex: Arad Sibiu Arad
2/22/2025
3
What are the different types of Agent?
Compare between simple reflex agent and model-based reflex agent.
Differentiate between goal based agent and utility-based agent.
Describe the problem formulation of the puzzle game.
Describe the problem formulation of the vacuum cleaner.
Assume you are in a vacation to Egypt, describe the problem
formulation if you are in Cairo and you want to go Luxor.
2/23/2025
2/22/2025
Reference resources
• Ertel, W. (2024). Introduction to artificial intelligence. Springer Nature.
• Russell, S. J., & Norvig, P. (2016). Artificial intelligence: a modern
approach. Pearson.
2/22/2025
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/15/2025
Lecture 4
Solving problems by searching
Uninformed search strategies
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/15/2025
Lecture Content
Searching for Solutions
Uninformed Search Strategies
Informed (Heuristic) Search Strategies
Heuristic Functions
3/15/2025
Recap
Autonomy
Adaption
Cooperation
3/15/2025
Agent
Sensors
?
Actuators
Environment
Fully observable vs. partially observable
Single agent vs. multiagent
Competitive vs. Cooperative
Deterministic vs. Stochastic
Episodic vs. Sequential
Static vs. dynamic
Discrete vs. Continuous
Recap
Simple reflex agents.
Model-based reflex agents.
Goal-based agents.
Utility-based agents.
3/15/2025
Goal-based agent environment properties
Static or dynamic?
Fully or partially observable?
Discrete or continuous?
Deterministic or stochastic?
Episodic or sequential?
Single agent or multiple agent?
3/15/2025
Example: Romania map
3/15/2025
General Search tree
Frontier means unexpanded node
3/15/2025
Search tree for Romania
The root node of the tree corresponds to the initial state,
(Arad).
The first step is to test whether this is a goal state.
Initial state
frontier
3/15/2025
Arad
State graph of Romania
3/15/2025
Search tree for Romania
(a) After expanding Arad
Arad
Sibiu
3/15/2025
Timisoara
Zerind
State graph of Romania
3/15/2025
Tree search for Romania
(c) After expanding Sibiu
Arad
Sibiu
Arad
Fagaras
Timisoara
Oradea
Zerind
Rimnicu
Vilcea
Loopy path: in which the path contains a repeated state in the search tree.
Ex: Arad Sibiu Arad
3/15/2025
Graph search
Traversing node means visiting this node
Explored node means visiting their children
Frontier means unexpanded node
3/15/2025
Graph search for Romania
The root node of the tree corresponds to the initial state,
(Arad).
The first step is to test whether this is a goal state.
Initial state
frontier
Arad
Frontier: Arad
1 Explored set: -
Traversing node means visiting this node
Explored node means visiting their children
Frontier means unexpanded node
3/15/2025
State graph of Romania
3/15/2025
Graph search for Romania
Frontier: Arad
1 Explored set: -
(a) After expanding Arad
2 Frontier: Sibiu, Timisora, Zerined
Explored set: Arad
Arad
Sibiu
3/15/2025
Timisoara
Zerind
frontier
State graph of Romania
3/15/2025
Tree for Romania using graph search
Frontier: Sibiu, Timisora, Zerined
2
Explored set: Arad
(c) After expanding Sibiu
Arad
Sibiu
Fagaras
Arad
3/15/2025
Timisoara
Oradea
Frontier: Arad
1 Explored set: -
3
Frontier: Timisora, Zerined,
Fagaras, Oradea,
Rimnci vilcea
Explored set: Arad, Sibiu
Zerind
Rimnicu
Vilcea
Don’t put Arad as it exists in
the explored set
Every time you expand a node, add it
to the explored set; don’t put the
explored set on the frontiers again.
Every time you add a node to the
frontier, check whether it already
exists with a higher path cost, and if
yes, replace that node with the new
one.
Tree for Romania using graph search
Frontier: Arad
1 Explored set: -
(c) After expanding Sibiu
2 Frontier: Sibiu, Timisora, Zerined
Arad
Explored set: Arad
Sibiu
Fagaras
Timisoara
Oradea
Zerind
3
Rimnicu
Vilcea
4
3/15/2025
Frontier: Timisora, Zerined,
Fagaras, Oradea,
Rimnci vilcea
Explored set: Arad, Sibiu
Frontier: Timisora, Zerined,
Fagaras, Oradea,
Rimnci vilcea
Explored set: Arad, Sibiu
Search algorithms
A search algorithm takes a problem as input and returns
a solution in the form of an action sequence.
Problem
3/15/2025
Input
Search algorithm
Action sequence
solution
Search algorithms
Uninformed search algorithms (blind)—algorithms that are given
no information about the problem other than its definition.
Informed search algorithms (heuristic) can do quite well given
some guidance on where to look for solutions.
Search algorithms
Informed search algorithms
3/15/2025
Uniformed search algorithms
Informed Search algorithms
Informed search algorithms (heuristic) can do quite well given
some guidance on where to look for solutions.
It contains an array of knowledge, such as how far we are
from the goal, path cost, how to reach to goal node, etc. .
This knowledge help agents to explore less to the search
space and find more efficiently the goal node.
3/15/2025
Search algorithms
Uninformed( Blind) search:
Breadth-first search
Depth-first search
Depth limited search
Iterative deepening search
Uniform cost search
Informed (Heuristic) search: search is guided by an evaluation
function:
Greedy best-first search
A* search
IDA* search
beam search
3/15/2025
Brute force search (Exhaustive search)
It assumes no additional knowledge other than
how to traverse the search tree and identify leaf
nodes and goal nodes.
It examines every node in the tree until it finds a
goal.
3/15/2025
Measuring problem-solving performance
“Properties of Search Methods”
Completeness: Is the algorithm guaranteed to find a solution
when there is one?.
Optimality: Does the strategy find the optimal solution?.
Time complexity: How long does it take to find the goal state?
Space complexity: How much memory is needed to perform the
search?
3/15/2025
Time and Space Complexity ?
Time and space complexity are measured in terms of:
Branching factor (b): maximum number of successors of any
node.
The length of a path to a goal is the depth d.
m: Maximum length of any path in the state space.
Start node
A
B
m=3
D
H
Depth=0
C
E
F
Depth=1
G
Depth=2
Max children of any node is b=2
27
Uniformed search algorithms
1. Breadth first search
2. Depth first search
3. Depth limited search
4. Iterative deepening search
5. Uniform cost search
3/15/2025
1. Breadth first search
1. Breadth- first search (BFS)
Breadth-first algorithm starts by examining all nodes one level
after another starting from the root node.
Implementation:
Use of a First-In-First-Out (FIFO) queue.
Nodes visited first are expanded first.
Start node
A
B
D
3/15/2025
C
E
F
G
Goal node
Breadth first search
A
A
B
D
3/15/2025
C
E
F
G
Breadth first search
A
AB
B
D
3/15/2025
C
E
F
G
Breadth first search
A
ABC
B
D
3/15/2025
C
E
F
G
Breadth first search
A
ABCD
B
D
3/15/2025
C
E
F
G
Breadth first search
A
ABCDE
B
D
3/15/2025
C
E
F
G
Breadth first search
A
ABCDEF
B
D
3/15/2025
C
E
F
G
Breadth first search
A
ABCDEFG
B
D
C
E
F
G
Goal is found
This search continues examining nodes in each level,
reporting success when a goal node is found, and
reporting failure if all nodes have been examined and
no goal node has been found.
3/15/2025
Breadth first search
In the worst case all the nodes will be
traversed in the tree and the time complexity
𝑑
will be O(𝑏 ).
3/15/2025
Stop traversing the tree if
the goal is found
Branching factor (b)=2
Number of nodes in level 0: 𝑏 0 =1
Number of nodes in level 1: 𝑏1 =2
Number of nodes in level 2: 𝑏 2 =4
Number of nodes in level 3: 𝑏 3 =8
Then the number of traversed
nodes at depth (d) will be =
𝑏 0 + 𝑏1 + 𝑏 2 + …. + 𝑏 𝑑 = 𝑂(𝑏 𝑑 )
Evaluation of tree-search strategies
Once a goal node is generated, it is the shallowest goal node as all the shallower
nodes must have been generated.
The shallowest goal node is not necessarily the optimal one.
BFS is optimal if the path cost is a nondecreasing function of the depth of the node.
3/15/2025
Time and memory requirements for breadth-first search
3/15/2025
Breadth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Bucharest
Ignore loopy path
Rimnicu
vilcea
Pitesti
Bucharest
Sibiu
3/15/2025
Fagaras
Rimnivu vilcea Bucharest
Breadth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Is it goal? No
Sibiu
3/15/2025
Breadth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Is it goal? No
Fagaras
Rimnicu
vilcea
Sibiu
3/15/2025
Fagaras
Breadth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Rimnicu
vilcea
Is it goal? NO
Sibiu
3/15/2025
Fagaras
Rimnicu vilcea
Breadth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Rimnicu
vilcea
Fagaras
Bucharest
Is it goal? Yes, then stop expanding.
Ignore loopy path
Sibiu
3/15/2025
Fagaras
Rimnivu vilcea Bucharest
Breadth first search
B
D
A
F
A
H
C
E
G
B
B
C
F
E
G
D
B
3/15/2025
H
E
2. Uniform cost search
Uniform cost search
When all step costs are equal, breadth-first search is optimal
because it always expands the shallowest unexpanded node.
Instead of expanding the shallowest node, uniform-cost
search expands the node n with the lowest path cost g(n).
It is guided by path costs rather than depths. Nodes are
ordered according to their path cost.
Expand least-cost unexpanded node
Equivalent to breadth-first if step costs all equal
Implementation:
3/15/2025
fringe = queue ordered by path cost
Uniform cost search using graph search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Bucharest
Rimnicu
vilcea
Pitesti
Bucharest
Ignore loopy path
3/15/2025
Uniform cost search
Sibiu
99
Fagaras
0
80
Rimnicu
vilcea
The successors of Sibiu are
Rimnicu Vilcea and Fagaras
with costs 80 and 99,
respectively.
3/15/2025
Uniform cost search
0
Sibiu
80
99
Rimnicu
vilcea
Fagaras
97
Pitesti
Sibiu
Now, we will Ignore loopy path and in the next iterations
3/15/2025
Uniform cost search
Sibiu
99
99
Fagaras
0
80
Rimnicu
vilcea
80
97
Pitesti
3/15/2025
177
Adding Pitesti with cost
80 + 97 = 177.
Uniform cost search
Sibiu
99
99
Fagaras
0
80
Rimnicu
vilcea
80
97
310
Bucharest
3/15/2025
Pitesti
177
The least-cost node is now
Fagaras, so it is expanded,
adding Bucharest with cost
99 + 211 = 310.
Don’t stop explore all other
paths.
Uniform cost search
Sibiu
99
99
Fagaras
211
310
Bucharest
0
80
Rimnicu
vilcea
80
97
Pitesti
177
101
Bucharest
3/15/2025
278
Now, a goal node is
generated, but uniform-cost
search keeps going, by
expanding Pitesti and adding
a second path to Bucharest
with cost 80+97+101 = 278.
Uniform Cost Search (UCS)
Sibiu
99
99
Fagaras
211
310
Bucharest
0
80
Rimnicu
vilcea
80
97
Pitesti
177
101
Bucharest
278
Sibiu Rimnicu vilceaPitesti Bucharest
3/15/2025
Now UCS checks if this new
path is better than the old
one; it is, so the old one is
discarded.
Bucharest, now with g-cost
278,
is
selected
for
expansion and the solution is
returned.
Uniform Cost Search (UCS)
Sibiu
99
99
Fagaras
211
310
Bucharest
0
80
Rimnicu
vilcea
80
97
Pitesti
177
101
Bucharest
278
Sibiu Rimnicu vilceaPitesti Bucharest
3/15/2025
Drawbacks
Uniform-cost search is guided by path
costs rather than depths, so its
complexity is not easily characterized in
terms of b and d.
let C∗ be the cost of the optimal solution
and assume that every action costs at
least ∈ . Then the algorithm’s worstcase time and space complexity is
O(𝑏1+𝐶∗/∈ ) which can be much greater
than 𝑏 𝑑 .
When all step costs are the same, UCS
is similar to BFS, except that the BFS
stops as soon as it generates a goal,
whereas UCS examines all the nodes at
the goal’s depth to see if one has a
lower cost; thus uniform-cost search
does strictly more work by expanding
nodes at depth d unnecessarily.
Evaluation of tree-search strategies
3/15/2025
3. Depth first search
Depth-first search (DFS)
Follows each path to its deepest node, before backtracking to try
the next path.
Start from the left side and work toward the right, depth-first
search involves working all the way down the left-most path in
the tree until a leaf node is reached. If this is a goal state, the
search is complete.
If the leaf node does not represent a goal state, search
backtracks up to the next highest node that has an unexplored
path.
3/15/2025
Depth-first search
3/15/2025
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
3/15/2025
I
C
E
J
F
k
L
G
M
N
O
Depth-first search
A
B
D
H
I
C
E
J
F
k
L
G
M
N
Goal node
3/15/2025
O
Depth first search
Given the following state space (tree search), give the
sequence of visited nodes when using DFS (assume that the
node O is the goal state):
A
B
F
A,B,F,
G,K,
L, O: Goal State
C
G
K
D
H
L
I
M
E
J
N
O
75
Depth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Bucharest
Ignore loopy path
3/15/2025
Rimnicu
vilcea
Pitesti
Bucharest
Sibiu
Depth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Bucharest
Ignore loopy path
Rimnicu
vilcea
Pitesti
Bucharest
Sibiu
3/15/2025
Fagaras
Depth first search
The problem is to get from Sibiu to Bucharest.
Sibiu
Fagaras
Bucharest
Ignore loopy path
Rimnicu
vilcea
Pitesti
Bucharest
Sibiu Fagaras Bucharest
3/15/2025
Breadth first search vs. depth first search
Breadth-first search is a poor idea in trees where all paths
lead to a goal node with similar length paths.
In situations such as this, depth-first search would perform
far better because it would identify a goal node when it
reached the bottom of the first path it examined.
Breadth first search vs. depth first search
Scenario
Some paths are
extremely long or even
infinite
All paths are of similar
length
All paths are of similar
length, and all paths lead
to a goal state
High branching factor
Depth first
Performs bad
Breadth first
Performs well
Performs well
Performs well
Performs well
Wasteful of time
and memory
Performance
depends on
other factors
Performs poorly
Evaluation of tree-search strategies
DFS needs to store only a single path from the root to a leaf node along
with the remaining unexpanded sibling nodes for each node on the path.
For a state space with branching factor b and maximum depth m, DFS
requires storage of only O(bm) nodes.
3/15/2025
4. Depth limited search
Depth-Limited Search (DLS)
Given the following state space (tree search), give the sequence
of visited nodes when using DLS (Limit = 2):
A
Limit = 0
B
Limit = 1
Limit = 2
F
C
G
K
D
H
L
I
M
E
J
N
O
83
Depth-Limited Search (DLS)
A,
A
B
C
D
E
Limit = 2
84
Depth-Limited Search (DLS)
A,B,
A
B
Limit = 2
F
C
D
E
G
85
Depth-Limited Search (DLS)
A,B,F,
A
B
Limit = 2
F
C
D
E
G
86
Depth-Limited Search (DLS)
A,B,F,
G,
A
B
Limit = 2
F
C
D
E
G
87
Depth-Limited Search (DLS)
A,B,F,
G,
C,
A
B
Limit = 2
F
C
G
D
E
H
88
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
A
B
Limit = 2
F
C
G
D
E
H
89
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,
A
B
Limit = 2
F
C
G
D
H
I
E
J
90
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I
A
B
Limit = 2
F
C
G
D
H
I
E
J
91
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I
J,
Limit = 2
A
B
F
C
G
D
H
I
E
J
92
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I
J,
E
Limit = 2
A
B
F
C
G
D
H
I
E
J
93
Depth-Limited Search (DLS)
A,B,F,
G,
C,H,
D,I
J,
E, Failure
Limit = 2
A
B
F
C
G
D
H
I
E
J
94
Depth-Limited Search (DLS)
DLS algorithm returns Failure (no solution)
The reason is that the goal is beyond the limit (Limit =2): the
goal depth is (d=4)
A
B
Limit = 2
F
C
G
K
D
H
L
I
M
E
J
N
O
95
Evaluation of tree-search strategies
DFS needs to store only a single path from the root to a node in limit (l)
along with the remaining unexpanded sibling nodes for each node on the
path.
For a state space with branching factor b and maximum limit l, DFS
requires storage of only O(bl) nodes.
3/15/2025
5. Iterative Deepening Search
IDE
Iterative Deepening Search
Strategy:
• Based on depth-limited (depth-first) search.
• Repeat search with gradually increasing depth limit until a
goal state is found.
Implementation:
for depth 0 to ∞ do
result depthLimitedSearch(problem, depth)
if result ≠ cutoff then return result
Iterative Deepening Search (IDS)
DLS with bound = 0
Iterative Deepening Search (IDS)
A,
Limit = 0
A
100
Iterative Deepening Search (IDS)
A, Failure
Limit = 0
A
101
Iterative Deepening Search (IDS)
DLS with bound = 1
Iterative Deepening Search (IDS)
A,
A
Limit = 1
B
C
D
E
103
Iterative Deepening Search (IDS)
A,B,
A
Limit = 1
B
C
D
E
104
Iterative Deepening Search (IDS)
A,B,
C,
A
Limit = 1
B
C
D
E
105
Iterative Deepening Search (IDS)
A,B,
C,
D,
Limit = 1
A
B
C
D
E
106
Iterative Deepening Search (IDS)
A,B
C,
D,
E,
Limit = 1
A
B
C
D
E
107
Iterative Deepening Search (IDS)
A,B,
C,
D,
E, Failure
Limit = 1
A
B
C
D
E
108
Iterative Deepening Search (IDS)
A,
A
B
C
D
E
Limit = 2
109
Iterative Deepening Search (IDS)
A,B,
A
B
Limit = 2
F
C
D
E
G
110
Iterative Deepening Search (IDS)
A,B,F,
A
B
Limit = 2
F
C
D
E
G
111
Iterative Deepening Search (IDS)
A,B,F,
G,
A
B
Limit = 2
F
C
D
E
G
112
Iterative Deepening Search (IDS)
A,B,F,
G,
C,
A
B
Limit = 2
F
C
G
D
E
H
113
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
A
B
Limit = 2
F
C
G
D
E
H
114
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,
A
B
Limit = 2
F
C
G
D
H
I
E
J
115
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I
A
B
Limit = 2
F
C
G
D
H
I
E
J
116
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I
J,
Limit = 2
A
B
F
C
G
D
H
I
E
J
117
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I
J,
E
Limit = 2
A
B
F
C
G
D
H
I
E
J
118
Iterative Deepening Search (IDS)
A,B,F,
G,
C,H,
D,I
J,
E, Failure
Limit = 2
A
B
F
C
G
K
D
H
L
I
M
E
J
N
O
119
Iterative Deepening Search (IDS)
DLS with bound = 3
Iterative Deepening Search (IDS)
A,
A
B
C
D
E
Limit = 3
121
Iterative Deepening Search (IDS)
A,B,
A
B
F
C
D
E
G
Limit = 3
122
Iterative Deepening Search (IDS)
A,B,F,
A
B
F
C
D
E
G
Limit = 3
123
Iterative Deepening Search (IDS)
A,B,F,
G,
A
B
F
Limit = 3
C
D
E
G
K
L
124
Iterative Deepening Search (IDS)
A,B,F,
G,K,
A
B
F
Limit = 3
C
D
E
G
K
L
125
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
A
B
F
Limit = 3
C
D
E
G
K
L
126
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,
A
B
F
Limit = 3
C
G
K
D
E
H
L
127
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
A
B
F
Limit = 3
C
G
K
D
E
H
L
128
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,
A
B
F
Limit = 3
C
G
K
D
H
I
E
J
L
129
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,
A
B
F
Limit = 3
C
G
K
D
H
L
I
E
J
M
130
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,M,
A
B
F
Limit = 3
C
G
K
D
H
L
I
E
J
M
131
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,M,
J,
Limit = 3
A
B
F
C
G
K
D
H
L
I
M
E
J
N
132
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,M,
J,N,
Limit = 3
A
B
F
C
G
K
D
H
L
I
M
E
J
N
133
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,M,
J,N,
E,
Limit = 3
A
B
F
C
G
K
D
H
L
I
M
E
J
N
134
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
C,H,
D,I,M,
J,N,
E,Failure
Limit = 3
A
B
F
C
G
K
D
H
L
I
M
E
J
N
O
135
Iterative Deepening Search (IDS)
DLS with bound = 4
Iterative Deepening Search (IDS)
A,
A
B
C
D
E
Limit = 4
137
Iterative Deepening Search (IDS)
A,B,
A
B
F
C
D
E
G
Limit = 4
138
Iterative Deepening Search (IDS)
A,B,F,
A
B
F
C
D
E
G
Limit = 4
139
Iterative Deepening Search (IDS)
A,B,F,
G,
A
B
F
C
D
E
G
K
L
Limit = 4
140
Iterative Deepening Search (IDS)
A,B,F,
G,K,
A
B
F
C
D
E
G
K
L
Limit = 4
141
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
A
B
F
D
E
G
K
Limit = 4
C
L
O
142
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L, O: Goal State
A
B
F
D
E
G
K
Limit = 4
C
L
O
143
Iterative Deepening Search (IDS)
It does this by gradually increasing the limit—first 0, then 1, then 2, and so on—until a
goal is found.
Like DFS, its memory requirements are modest: O(bd).
Like BFS, it is complete when the branching factor is finite and optimal when the path
cost is a nondecreasing function of the depth of the node. (optimal if step costs are all
identical or increasing)
Iterative deepening search may seem wasteful because states are generated multiple
times. It turns out this is not too costly. The reason is that in a search tree with the same
(or nearly the same) branching factor at each level, most of the nodes are in the bottom
level, so it does not matter much that the upper levels are generated multiple times.
It gives a time complexity of O(b)—asymptotically the same as breadth-first search.
Assignment 4
• Depth first search is implemented using …………….. data structure.
• Breadth first search is implemented using …………….. data structure.
Iterative Deepening Search (IDS)
• In general, IDS is the preferred uninformed search method
when the search space is large and the depth of the solution is
not known.
Evaluation of tree-search strategies
The total number of nodes generated in the worst case is
Assignment 4
Given the following state space (tree search), give the
sequence of visited nodes when using BFS, DFS, IDS,
DLS (assume that the node O is the goal state):
A
B
F
C
G
K
D
H
L
I
M
E
J
N
O
148
Reference resources
• Coppin, B. (2004). Artificial intelligence illuminated. Jones & Bartlett
Learning.
• Ertel, W. (2024). Introduction to artificial intelligence. Springer Nature.
• Russell, S. J., & Norvig, P. (2016). Artificial intelligence: a modern
approach. Pearson.
3/15/2025
3/15/2025
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/15/2025
Lecture 5
Solving problems by searching
Informed search strategies
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/15/2025
Lecture Content
Informed (Heuristic) Search Strategies
Greedy best first search
A* search
Heuristic Functions
3/15/2025
Solve using uniform cost search
5
B
c
2
10
8
3
A
D
F
11
6
4
2
7
E
G
5
Initial state: A
Goal state: F
3/15/2025
3
Uniform cost search
Uniform cost search is optimal, complete, but inefficient in time and
space.
Greedy best first search is not optimal, not complete, but efficient
and directed based on selecting good heuristic.
3/15/2025
3/15/2025
Goal-based agent environment properties
Static or dynamic?
Fully or partially observable?
Discrete or continuous?
Deterministic or stochastic?
Episodic or sequential?
Single agent or multiple agent?
3/15/2025
Example: Romania map
“Distance in kilometer”
3/15/2025
Search algorithms
uninformed( Blind) search:
breadth-first search
depth-first search
depth limited search
iterative deepening search
bidirectional search
Informed (heuristic) search: search is guided by an evaluation
function:
Greedy best-first search
A* search
Recursive best-first search
3/15/2025
Using problem specific knowledge to aid searching
With knowledge, one can search the state space as if he
was given “hints” when exploring a maze.
Heuristic information in search = Hints
Leads to dramatic speed up in efficiency.
A
Search only in this
subtree !!
C
B
F
G
K
D
H
L
O
I
M
E
J
N
Greedy best-first search
The algorithm is called “greedy” as it expands the node that
is closest to the goal.
It evaluates nodes using the heuristic function: f(n)=h(n).
h(n): the straight line distance from node n to goal state.
Note: hSLD values cannot be computed from the problem
description. Moreover, it is a useful heuristic to know that hSLD
is correlated with actual road distances.
The implementation of best-first search is identical to that for
uniform-cost search, except for the use of h(n) instead of g(n)
to order the priority queue.
Greedy best-first search: Example 1
Evaluation-function: f(n) = h(n)
h(n)
If n is goal then h(n)=0
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
State graph of Romania
h(n)
366
3/15/2025
Greedy best-first search (tree search version)
Initial state
frontier
Arad
366
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
Greedy best-first search (tree search version)
Initial state
frontier
Arad
366
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
State graph of Romania
374
3/15/2025
State graph of Romania
253
3/15/2025
State graph of Romania
329
3/15/2025
Greedy best-first search
Sibiu
253
Arad
366
Timisoara
329
Zerind
374
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
State graph of Romania
176
3/15/2025
State graph of Romania
193
3/15/2025
State graph of Romania
380
3/15/2025
State graph of Romania
366
3/15/2025
Greedy best-first search
Arad
366
Timisoara
329
253
Sibiu
Zerind
Arad
Fagaras
Oradea
Rimnicu
Vilcea
366
176
380
193
374
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Iasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
Greedy best-first search
Arad
366
Timisoara
329
Arad Sibiu Fagaras Bucharest
h(n) = 366
from Arad to Buchrest
dist(n) = 140 + 99 + 211 = 450
253
Sibiu
Arad
366
Fagaras
176
Oradea
Rimnicu
Vilcea
380
193
Sibiu
Bucharest
253
0
Goal state
Zerind
374
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Iasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
Greedy best-first search
“tree search version”
Complete? No, is incomplete even
in finite state space, much like depthfirst search.(graph search)
Consider the problem of getting from Iasi
to Fagaras.
Iasi
Vaslui
Neamt
Dead end
The heuristic suggests that Neamt be
expanded first because it is closest to
Fagaras, but it is a dead end.
Iasi
Vaslui
Neamt
Vaslui
Iasi
Neamt
Greedy best-first search
“tree search version”
Arad Sibiu Fagaras Bucharest
h(n) = 366
from Arad to Buchrest
dist(n) = 140 + 99 + 211 = 450
Optimal? No, since the algorithm only considers the heuristic
value and ignores edge weights, it may find a solution that isn’t
the shortest or least costly.
There are another path with lower cost value:
Arad Sibiu Rimnicu Vilcea PitestiBucharest = 144 + 80 +
97 + 101 = 422 km
Time? O(bm) -- but a good heuristic can give dramatic
improvement.
Space? O(bm) -- keeps all nodes in memory.
Greedy best-first search
We stop when the node with the lowest f-value is a goal
state.
Is this guaranteed to find the shortest path?
No. Because it always selects the node with the smallest
heuristic value, Greedy Best-First Search may quickly find a
path, but it does not guarantee finding the shortest path
unless the heuristic satisfies certain conditions (complete
and optimal)
A* search
Greedy search minimizes a heuristic h(n) which is an
estimated cost from a node n to the goal state. However,
although greedy search can considerably cut the search
time (efficient), it is neither optimal nor complete.
Uniform-Cost Search minimizes the cost g(n) from the
initial state to n. It is optimal and complete but not
efficient.
New Strategy (A* search): Combine greedy search and
uniform-cost search to get an efficient algorithm which
is complete and optimal.
Heuristic Functions
g(n) = The path cost from the initial state to node n.
h(n) = The straight line distance from node n to the goal state.
Three approaches to define f(n):
1. f (n) = g(n) Uniform cost search “not heuristic function alone”
2. f(n) = h(n) Greedy best-first search
3. f(n) = g(n) + h(n) A* search
hSLD(n) = straight-line
distance from n to
Bucharest
30
A* search
It is the best-known form of best-first search.
It is identical to uniform-cost search except that A* uses g + h
instead of g. If h(n) =0 for all nodes.
It avoids expanding paths that are already expensive.
Evaluation function: f(n)=g(n) + h(n)
g(n) = The path cost from the initial state to node n.
h(n) = The straight line distance from node n to the goal state.
f(n): The estimated cost of the cheapest solution through n.
It finds the cheapest solution, a reasonable thing to try first is the
node with the lowest value of g(n)+h(n).
A* search
Arad
366=0+366
Arad has the cheapest cost of 366 among frontiers
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
State graph of Romania
3/15/2025
A* search using tree search
Arad
393=140+253
Sibiu
366=0+366
447=118+329
449=75+374
Timisoara
Zerind
Sibiu has the cheapest cost of 393 among frontiers
Note: frontiers are colored with pink color.
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
A* search using tree search
Arad
393=140+253
Sibiu
366=0+366
447=118+329
449=75+374
Timisoara
Zerind
646=280+366
415=239+176
671=291+380
Arad
Fagaras
Oradea
413=220+193
Rimnicu
Vilcea
Rimnicu Vilcea has the cheapest cost of 413 among frontiers
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
A* search
Arad
393=140+253
Sibiu
366=0+366
447=118+329
449=75+374
Timisoara
Zerind
646=280+366
415=239+176
671=291+380
Arad
Fagaras
Oradea
Rimnicu
Vilcea
526=366+160
417=317+100
Craiova
413=220+193
Pitesti
553=300+253
Sibiu
Fagaras has the cheapest cost of 415 among frontiers
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
A* search
Arad
393=140+253
Sibiu
366=0+366
447=118+329
449=75+374
Timisoara
Zerind
646=280+366
415=239+176
671=291+380
Arad
Fagaras
Oradea
Rimnicu
Vilcea
526=366+160
417=317+100
Craiova
Pitesti
591=338+253
Sibiu
450=450+0
Bucharest
413=220+193
553=300+253
Sibiu
Pitesti has the cheapest cost of 417 among frontiers
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
A* search
Arad
393=140+253
Sibiu
366=0+366
447=118+329
449=75+374
Timisoara
Zerind
646=280+366
415=239+176
671=291+380
Arad
Fagaras
Oradea
413=220+193
Rimnicu
Vilcea
591=338+253
450=450+0
526=366+160
417=317+100
Sibiu
Bucharest
Craiova
Pitesti
Goal
553=300+253
Sibiu
Bucharest
Craiova
Rimnicu
Vilcea
418=418+0
615=455+160
607=414+193
Arad
Bucharest
Craiova
Drobeta
Eforie
Fagaras
Giurgiu
Hirsova
Lasi
Lugoj
Mehadia
Neamt
Oradea
Pitesti
Rimnicu Vilcea
Sibiu
Timisora
Urziceni
Vaslui
Zerind
366
0
160
242
161
176
77
151
226
244
241
234
380
100
193
253
329
80
199
374
Properties of A* search
Complete? Yes (unless there are infinitely many nodes)
Time? Exponential
Space? Keeps all nodes in memory
Optimal? Yes
A* search
A∗ search is both complete and optimal.
It has the following properties:
The tree-search version of A* is optimal if h(n) is admissible.
The graph-search version A* is optimal if h(n) is consistent.
A heuristic h(n) is admissible if for every node n
h(n) ≤ h*(n),
where h*(n) is the true cost to reach the goal state from n.
An admissible heuristic never overestimates the true cost
from node n to reach the goal. h*(n) = c(n, goal)
Consistency (monotonic)
Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is
optimal.
A heuristic is consistent if for every node n, every successor n' of
n generated by any action a
h(n) ≤ c(n,a,n') + h(n')
Any consistent heuristic is admissible.
3
Admissible?
3
4
3
A
2
S
1
C
7
G
2
B
3
10
3
3
A
2
S
C
7
G
2
B
3
5
S h(S)=4
4<= 2+3+7 ✔
4<=2+2+4 ✔
4<=1+5+4 ✔
4<=1+10 ✔
C
7
2
1
G
2
B
5
3
C h(C)=1
1<=7 ✔
D
0
4
10
D h(D)=2
2<=4 ✔
1
2
1
0
4
D
5
2
4
3
A
S
2
1
4
Start state: S
Goal state: G
1
D
10
4
0
A h(A)=3
3<= 3+7 ✔
3<=2+4 ✔
B h(B)=3
3<=5+4 ✔
3<=10 ✔
Yes, Since for every node n
h(n) ≤ h*(n)
where h*(n) is the true cost to
reach the goal state from n.
Consistent?
Start state: S
Goal state: G
3
4
3
A
2
S
1
C
7
2
1
G
2
B
3
5
D
S 4<=3+2 ✔
4<=3+1 ✔
0
4
10
Yes, As for every node n: h(n) ≤ c(n, a, n') + h(n'),
where n' is a successor of n.
A 3<=1+3 ✔
3<=2+2 ✔
B 3<=2+5 ✔
3<=0+10 ✔
C 1<=0+7 ✔
D 2<=0+4 ✔
Uninformed search algorithms
Informed search algorithms
Assignment 5
Solve using BFS, DFS, DLS, IDS, greedy search and A* search using both
tree search and graph search
A
118
111
Start
75
B
140
C
D
E
80
99
G
F
97
H
101
211
I
Goal
State
A
B
C
D
E
F
G
H
I
Heuristic: h(n)
366
374
329
244
253
178
193
98
0
46
Example 2
• Initial state: Linz
• Goal state: Ulm
Straight-line distance to Ulm
Example 3
Straight-line distance h(n)
5
B
11
6
4
A
c
2
3
8
7
2
D
E
F
10
G
5
3
A
B
C
28
30
56
D
E
F
G
60
44
10
36
48
Determine if the following graph is admissible and
consistent for using the following heuristics h1, h2:
State
S
A
B
C
D
G
h1
5
3
6
2
3
0
h2
4
2
6
1
3
0
Reference resources
• Coppin, B. (2004). Artificial intelligence illuminated. Jones & Bartlett
Learning.
3/15/2025
3/15/2025
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/17/2025
Lecture 6
Game theory (Adversarial search)
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
3/17/2025
Lecture Content
What is adversarial search?
Typical assumptions
Different types of games.
Adversarial search formulation
Adversarial search algorithms
Min-max algorithms
Alpha beta pruning
3/17/2025
Adversarial search
Adversarial search is a technique in AI that
deals with decision-making problems where
multiple agents compete against each other.
These agents often have conflicting goals,
making zero-sum game—one agent’s gain is
another’s loss.
It is a cornerstone of game theory and forms
the foundation for AI systems in competitive
environments.
Adversarial search problems are called games.
3/17/2025
Typical assumptions
Two agents whose actions alternate in a
competitive environment.
Environment
is
fully
observable,
deterministic, turn-taking and zero-sum
games.
A zero-sum game is one where the total
utility of all players is the same for every
instance of the game.
Ex: Chess is zero-sum because every game
has utility of either 0+1, 1+0 or 1/2+1/2.
3/17/2025
Turn-taking
Different types of games
•
•
•
•
•
•
Tic-Tac-Toe
Checkers
Chess
Go
Nim
Othello
These games are all observable because every player
always knows the complete game state.
Games for two players, such as chess, checkers, Othello,
and Go are deterministic because each move results in
the same child state given the same parent state.
In contrast, backgammon is stochastic because its child
state depends on the result of a dice roll.
3/17/2025
Adversarial search formulation
Initial state: specifies how the game is set up at the start.
Players: Defines which player has the move in a state.
Actions: the set of legal moves in a state.
Transition model: defines the result of a move.
Terminal-test: which is true when the game is over and false otherwise.
States where the game has ended are called terminal states.
Utility or objective function: defines the final numeric value for a game
that ends in terminal state for a player.
3/17/2025
Partial Tic-Toc-Toe tree
3/17/2025
Initial state is the root
node.
MAX
moves
first,
placing an X in an
empty square.
The
tree
shows
alternating
moves
between MIN (O) and
MAX (X), until reaching
terminal states, which
can
be
assigned
utilities according to
game rules.
-1: X lose
0: X draw
+1: X win
Adversarial search algorithms
They are designed to help agents evaluate and select the optimal
moves in competitive environments.
They simulate potential future actions and counteractions to
identify the best strategy.
Two of the most widely used algorithms are the Minimax
algorithm and Alpha-Beta pruning.
3/17/2025
Minimax Algorithm
The goal of each player is to make optimal moves that result in
victory.
Opponents are referred to by MIN and MAX.
MAX player is trying to Maximize his opportunity to win
(choose moves with the highest value).
MIN player is trying to Minimize MAX’s opportunity to win
(reduce the maximizer’s score).
3/17/2025
Example: Two-ply game tree
MAX
The▲ nodes are “MAX nodes” in which it is MAX’s turn to move and the▼
nodes are “MIN nodes.”
The terminal nodes show the utility values for MAX
MAX’s best move at the root is a1, because it leads to the state with the
highest minimax value MIN’s best reply is b1, because it leads to the state
with the lowest minimax value
3/17/2025
Minimax tree Example
3/17/2025
Time complexity O(𝑏 𝑑 )
Space complexity is O(𝑏 𝑑 )
𝒃𝟎 +𝒃𝟏 +𝒃𝟐 +…+𝒃𝒅 = O(𝒃𝒅 )
d: is the depth of the tree
b: is the branching factor
Minimax tree Example
3/17/2025
Alpha-beta pruning
Alpha–beta pruning is a search algorithm that seeks to decrease the
number of nodes that are evaluated by the minimax algorithm in its
search tree.
Alpha-beta pruning can be applied at any depth of a tree, and
sometimes it not only prune the tree leaves but also entire sub-tree.
Condition for Alpha-beta pruning:
if α>=β then prune
3/17/2025
Alpha-beta pruning
α: MAX’s best option on path to root
β: MIN’s best option on path to root
A search space is explored in depth-first down to the full ply depth.
Apply heuristic evaluation to a state and all its siblings.
For MIN nodes, the maximum is backed up to their parent (a MAX
node).
For MAX nodes, the minimum is backed up to their parent (a MIN node).
This value is offered to the grandparent as Beta value for MIN nodes, or
Alpha value for MAX nodes.
Alpha is a value associated with MAX nodes, that can never decrease.
Beta is a value associated with MIN nodes, that can never increase.
3/17/2025
Example 1
3
3/17/2025
4
7
2
8
1
Example 1
Max (∝)
Min (𝜷)
Max (∝)
3/17/2025
3
4
7
2
8
1
Example 1
Max (∝)
<=3
Min (𝜷)
Max (∝)
3/17/2025
3
4
7
2
8
1
Example 1
Max (∝)
<=3
Min (𝜷)
Max (∝)
3
4
7
2
8
1
Compare 3 with second child 4, Beta will remain 3
3/17/2025
Example 1
Max (∝)
<=3 3
Min (𝜷)
Max (∝)
3
4
7
2
8
1
Compare Beta value 3 with third child 7, Beta will remain 3
3/17/2025
Example 1
Max (∝)
>=3
Min (𝜷)
3
Max (∝)
3
4
7
2
8
1
Alpha=3 is a value associated with player max
3/17/2025
Example 1
Max (∝)
>=3
Min (𝜷)
3
Max (∝)
3/17/2025
3
4
7
2
8
1
Example 1
Max (∝)
>=3
Min (𝜷)
3
Max (∝)
3
4
<=2
7
Beta value will be <= 2
3/17/2025
2
8
1
Example 1
Max (∝)
>=3
Min (𝜷)
3
Max (∝)
3
4
2
7
2
<=2
8
1
Compare beta value with alpha value, if the alpha>=beta
value, prune the rest of the tree 3>=2 yes
3/17/2025
Example 1
3
Max (∝)
3
Min (𝜷)
Max (∝)
3
4
2
7
2
<=2
8
1
Compare beta value with alpha value, if the alpha>=beta
value, prune the rest of the tree 3>=2 yes
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Alpha-beta pruning
3/17/2025
Complexity of alpha beta algorithm
Alpha-beta algorithm performs a complete depth-first exploration of
the game tree.
m: maximum depth of the tree
b: legal moves at each point
Time complexity: O(𝑏 𝑚 ).
Space complexity: O(bm) if algorithm generates all actions at once or
O(m) if algorithm generates actions one at a time.
3/17/2025
Assignment 6
Max (∝)
Min (𝜷)
Max (∝)
3/17/2025
Assignment 6
3/17/2025
Assignment 6
3/17/2025
3/17/2025
CS203
Artificial intelligence
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
4/19/2025
Lecture 7
Fuzzy sets and fuzzy logic
Dr. Doaa El-Shahat
Lecturer at Computer Science Department
Zagazig University, Egypt
4/19/2025
Lecture Content
4/19/2025
4
Set
• Set is a collection of elements.
– Crisp set.
– Fuzzy set.
5
The crisp set
The crisp set is also called classical = traditional
=conventional =ordinary sets.
Crisp means clean, clear and sharp.
The set is a collection of elements.
Each element either belongs to the set or it does not
(member or not member),(true or false), (zero or one).
6
The crisp set
Examples:
A={x|x is even natural number}
A={x|x=2n,n is natural number}
A={apple, orange, mango}
A={a, b , c, d, e, i, y}
1 𝑖𝑓 𝑥 ∈ 𝐴
Membership or characteristic function: 𝜇𝐴 𝑥 = 0 𝑖𝑓 𝑥 ∉ 𝐴
A={x|x is even natural number}.
𝝁𝑨 𝟓 =0, 𝝁𝑨 𝟒 = 𝟏
A={apple, orange, mango}. 𝝁𝑨 𝒂𝒑𝒑𝒍𝒆 = 𝟏
7
Operations on crisp sets
• Union:
A B = {x | x A or x B}
• Intersection:
A B = {x | x A and x B}
• Complement:
A’ = {x | x A, x X}
• Difference:
A | B = {x | x A and x B}
It is also denoted by A - B
8
Properties of the crisp sets
•
•
•
•
AB=BA
AB=BA
A (B C) = (A B) C
A (B C) = (A B) C
• A (B C) = (A B) (A C)
• A (B C) = (A B) (A C)
•
•
•
•
•
•
AA=A
AA=A
AU=U
AU=A
A=A
A=
9
Crisp set
• A crisp set is defined by sharp
boundaries and contain the
precise location of the set
boundaries.
• It is clear that an element either
belongs to a set or does not
belong to that set in the classical
set and its operation.
• The temperature can be divided into
three categories: LOW (0~30°F),
MEDIUM (30°F~70°F) and HIGH
(70~120°F) and the boundary is
crystal clear.
10
Origins of fuzzy logic
Lotfi Asker Zadeh ( 1965 )
First to publish ideas of fuzzy logic.
Professor Toshire Terano ( 1972 )
Organized the world's first working group on fuzzy
systems.
F.L. Smidth & Co. ( 1980 )
First to market fuzzy expert systems.
Crisp/classical vs. fuzzy sets
12
The temperature 40°F belongs to LOW with 0.5 degree, but at the
same time it belongs to MEDIUM to about 0.7 degree.
The temperature 50°F, can be considered to belong to LOW and
HIGH to around degree and belong to MEDIUM to almost 1 degree
Fuzzy set
Fuzzy – “not clear, vague, not distinct, or not precise”.
• A set defined by membership functions is a fuzzy set.
• Given a fuzzy set A and an element x, “x is a member of A”
is not necessarily either true or false(0 or 1).
• In fuzzy set, each possible element has its degree of
membership ∈ [𝟎, 𝟏].
•
𝜇𝐴 𝑥 → [0, 1]
14
Example (Discrete Universe)
Given a universe U={1,2,3,4,5,6,7,8}. The fuzzy set A can be
represented as:
First representation: A={(1,0.1),(2,0.3),(3,0.8),(4,1),(5,0.9),(6,0.5),(7,0.2),(8,0.1)}
Second representation: A A ( xi ) / xi
xi U
A 0.1/ 1 0.3/ 2 0.8/ 3 1.0 / 4 0.9 / 5 0.5/ 6 0.2 / 7 0.1/ 8
15
Example (Continuous Universe)
possible ages
U : the set of positive real numbers
B ( x, B ( x )) x U
B ( x)
1
x 50
1
5
4
1.2
1
B ( x)
Alternative Representation:
B
about 50 years old
0.8
0.6
0.4
0.2
1
R 1 x 550
4
x
0
0
20
40
x : age
60
80
100
16
Alternative Notation
A ( x, A ( x )) x U
U : discrete universe
A A ( xi ) / xi
U : continuous universe
A A ( x) / x
xi U
U
Note that and integral signs stand for the union
of membership grades; “ / ” stands for a marker
and does not imply division.
17
Fuzzy set
• A fuzzy set is determined by its
indeterminate boundaries, there exists an
uncertainty about the set boundaries.
• For example, the temperature 40°F can
be considered to belong to LOW to a
certain degree, say 0.5 degree, but at the
same time it can belong to MEDIUM to
about 0.7 degree.
18
Linguistic variable
• Fuzzy terms are reffered as linguistic variables.
• Linguistic variable is a term used in our natural
language to describe some concept that usually has
vague or fuzzy values.
• Each linguistic variable has name, fuzzy sets.
• Example
Name
Temprature
Height
Speed
Price
Fuzzy sets
hot, cold, warm, cool.
short, medium, tall.
slow, fast, creepting.
cheap, expensive.
19
Hedges
• Hedges are qualifiers of a linguistic variable.
All purpose: very, quite, extermely.
Probability: likely, unlikely.
Quantifiers: most several, few.
Possability: almost, impossible, quite possible.
20
Linguistic variable
• Example:
Jhon is very tall.
• Name: height.
• Fuzzy set: tall.
• Hedge: very.
21
Natural Language
Consider:
Joe is tall
-- what is tall?
Joe is very tall -- what does this differ from tall?
Natural language (like most other activities in life and
indeed the universe) is not easily translated into the
absolute terms of 0 and 1.
“false”
“true”
22
Example: “Young”
Example:
Ann is 28,
Bob is 35,
Charlie is 23,
0.8 in set “Young”
0.1 in set “Young”
1.0 in set “Young”
Unlike statistics and probabilities, the degree is not
describing probabilities that the item is in the set,
but instead describes to what extent the item is the
set.
23
Membership function of fuzzy logic
Fuzzy values
Degree of
Membership
1
Young
Middle
Old
25
40
55
0.5
0
Age
Fuzzy values have associated degrees of membership in the set.
24
Example II
Linguistic Variable : temperature
Linguistics Terms (Fuzzy Sets) : {cold, warm, hot}
(x)
1
cold
warm
20
hot
60
x
25
Crisp vs fuzzy
Basis for
comparison
Fuzzy Set
Crisp Set
Basic
Prescribed by vague or
ambiguous properties.
Defined by precise and
certain characteristics.
Property
Elements are allowed to be
partially included in the set.
Element is either the
member of a set or not.
Applications
Used in fuzzy controllers
Digital design
Logic
multi-valued logic
bi-valued logic
26
Fuzzy sets: basic concepts
• Consider three fuzzy sets that represent the concepts of a young,
middle-aged, and old person. The membership functions are defined
on the interval [0,80] as follows:
Find line passing through
(x,y) and (20,1):
1/[35-20] = y/[35-x]
27
Fuzzy sets: basic concepts
28
Operations of fuzzy sets
• The complement of fuzzy set A with respect to the universal set X is
x X
defined for all
by the equation
A ( x ) 1 A( x )
A ( x) A( x)
• Elements of X for which
are called equilibrium points of A. For example,
the equilibrium points of A2 in Fig. 1.7 are 27.5 and 52.5.
29
Operations on fuzzy sets
• Equality of fuzzy sets
• Containment of fuzzy sets
• Complement of a fuzzy set
• Intersetion of fuzzy sets (AND)
• Union of fuzzy sets (OR)
30
Equality of two fuzzy sets
• For crisp sets, sets are equal if the two sets have exactly the
same elements.
• For fuzzy sets, however, equality cannot be concluded if the two
sets have the same elements. The degree of membership of
elements to the sets must also be equal. That is, the
membership functions of the two sets must be the same.
• Therefore, two fuzzy sets A and B are equal if and only if the sets
have the same domain, and μA(x) = μB(x) for all x ∈ X. That is, A=B.
• Example:
domain
X={1,2,3},
A={(1,0.1),(2,0.5),(3,0.4)},
B={(1,0.1),(2,0.5),(3,0.4)}
31
Containment of fuzzy sets
• For crisp sets, A ⊂ B if all the elements of A are also
elements of B.
• For fuzzy sets, this definition is not complete, and the
degrees of membership of elements to the sets have to
be considered.
• Fuzzy set A is a subset of fuzzy set B if and only if μA(x) ≤
μB(x) for all x ∈ X. That is, A ⊂ B.
32
Complement of a fuzzy set (NOT)
• The complement of a crisp set is simply the set containing
the entire domain without the elements of that set.
• For fuzzy sets, the complement of the set A consists of all
the elements of set A, but the membership degrees differ.
Let A denote the complement of set A. Then, for all x∈X,
μA(x)=1−μA(x). It also follows that A∩ 𝐴 =∅ and A∪𝐴=X. (T
or F)
33
Fuzzy sets
34
Complement of A
35
Intersection of fuzzy sets (AND)
• The intersection of crisp sets is the set of elements occurring in
both sets.
• Operators that implement intersection are referred to as tnorms. The result of a t-norm is a set that contain all the
elements of the two fuzzy sets, but with degree of membership
that depends on the specific t-norm. A number of t-norms have
been used, of which the min-operator and the product operator
are the most popular. If A and B are two fuzzy sets, then
– Min-operator: μA∩B(x) = min{μA(x),μB(x)}, ∀x ∈ X.
36
Intersection of fuzzy sets (AND)
37
Intersection
38
Union of fuzzy sets (OR)
• The union of crisp sets contains the elements of all of the
sets.
• The same is true for fuzzy sets, but with membership
degrees that depend on the specific union operator used.
These operators are referred to as s-norms, of which the
max-operator and summation operator are most frequently
used:
– Max-operator: μA∪B(x) = max{μA(x),μB(x)}, ∀x ∈ X
39
Union of fuzzy sets (OR)
40
Fuzzy set characteristics
• Normality
• Height
• Cardinality
• Support
• Core
• ∝ −𝑐𝑢𝑡
41
Normality
• A fuzzy set A is normal if that set has an element that belongs to the set
with degree 1. That is,
∃x ∈ A • μA(x) = 1
• then A is normal, otherwise, A is subnormal.
42
Fuzzy set characteristics
• The height of a fuzzy set is
defined as the supremum of the
membership function, i.e.
height(A) = sup μA(x)
• The support of fuzzy set A is the
set of all elements in the universe
of discourse, X, that belongs to A
with non-zero membership. That
is,
support(A) = {x ∈ X|μA(x) > 0}
• The core of fuzzy set A is the set
of all elements in the domain
that belongs to A with
membership
degree
1.
core(A) = {x ∈ X|μA(x) = 1}
43
Fuzzy set characteristics
• α-cut: The set of elements of A with membership degree
greater than α is referred to as the α-cut of A:
Aα = {x ∈ X|μA(x) ≥ α}
44
Fuzzy set characteristics
•
The cardinality of crisp sets is simply the number of elements within the
sets.
•
The cardinality of fuzzy set A, for a finite domain, X, is defined as card(A)
= 𝑥∈𝑋 μA(x)
•
•
•
•
•
For example, X = {a, b, c, d}, and A = 0.3/a + 0.9/b + 0.1/c + 0.7/d,
Cardinality (A) or |A| = 0.3 + 0.9 + 0.1 + 0.7 = 2.0.
Height(A)=0.9.
Support of (A)={a, b, c, d}
Core(A)=∅ no elements with membership=1.
45
Fuzzy Sets Example
Consider the following two fuzzy sets:
Universe={1,2,3,4,5}
A = { 1/2 + 0.5/3 + 0.3/4 + 0.2/5}
B = {0.5/2 + 0.7/3 + 0.2/4 + 0.4/5}
𝐴= { 1/1 + 0/2 + 0.5/3 + 0.7/4 +0.8/5}
𝐵 = { 1/1 + 0.5/2 + 0.3/3 + 0.8/4 +0.6/5}
Union: A U B = {1/2 + 0.7/3 + 0.3/4 +0.4/5}
Intersection: A ∩B = {0.5/2 + 0.5/3 + 0.2/4 +0.2/5}
46
47
48
Boolean logic
In Boolean logic, only two possibilities (0 and 1) exist,
where 1 denotes the absolute truth value and 0 denotes
the absolute false value.
49
Fuzzy logic
In fuzzy logic, there are multiple possibilities present
between the 0 and 1, which are partially false and
partially true.
Fuzzy logic can be implemented in systems, such as:
micro-controllers
workstation-based or large network-based systems
for achieving the definite output.
Fuzzy logic can also be implemented in both hardware or
software
50
4/19/2025
Lec. 5
Artificial neural network
Faculty of Computers and Informatics, Computer
Science Department, Zagazig University, Egypt
Artificial neural network
Artificial neural network (ANN) can be defined as an
information-processing model inspired by the biologcal
nervous systems (biological neural network), such as the
brain.
This model tries to replicate the most basic functions of the
brain.
ANN is an architecture consisting of a large number of
neurons organized in different layers and the neurons of
one layer are connected to those of another layer by
means of weights.
By Doaa El-Shahat
3
Biological neural network
The human brain consists of nearly 1011 of neurons and
60 trillion connections (synapses) among them.
Each neuron has a very simple structure, but a huge
number of such neurons constitute a tremendous
processing power.
By using multiple neurons simultaneously, the brain can
perform its functions in parallel and much faster than the
fastest computers.
The information is stored and processed simultaneously
throughout the whole network rather than specific
locations. In other words, processing is global rather than
local.
By Doaa El-Shahat
4
Biological neural network
Dendrites
The biological neuron consists of three
main parts:
Soma or cell body: where the cell
nucleous is located.
Dendrites: where the nerve is
connected to the cell body
Axon: which carries the impulses
of the neuron
Synapse is that part of a neuron,
where its axon contacts the
dendrites
of
its
neighboring
neuron.
Soma
Axon
Synapse
5
Biological neural network
The
neurons
are
communicating with each
other with the help of
electrical impulses.
6
Biological neural network
A neuron collects information from its
neighbors with the help of its dendrites.
The collected information is then
summed up in the cell body, before it
passes
through
the
axon.
This
information is then transferred to the next
neuron through the synapse.
Learning is a fundamental and
essential characteristic of biological
neural network.
7
Brain vs. computer
ANN
BNN
Speed
Faster in processing
information.Response
time is nanosecond.
Slower in processing information.
Response time in milliseconds
processing
Serial processing
Massively parallel processing
Size
and
complexity
Less
size
complexity
Storage
Replaceable
Information storage:
replacing new data
with old data.
&
Highly complex
Information storage is adaptable
means such that new information is
added by adjusting the interconnection
strengths without destroying old
information
By Doaa El-Shahat
8
Brain vs. computer
ANN
Fault
tolerance
BNN
Information
once It
possesses
fault
corrupted cannot be tolerance as it can store
retrieved in case of and retrieve information.
failure of the system
By Doaa El-Shahat
9
Artificial neural network
ANN consists of a
number
of
very
simple processors,
also called neurons,
which are analogous
to the biological
neurons in the brain.
By Doaa El-Shahat
10
Artificial neuron
Biological NN
Artificial NN
Cell
Neuron
Dendrite
Input
Soma
Net input
Synapse
weight
Axon
Output
By Doaa El-Shahat
11
Basic concept of ANN
Dendrites are represented as input signal where data, such as
features or variables for problem solving will be provided here.
Cell body or soma is where linear combination computation
( ) and activation function f ( ) is applied.
Axon is represented as output signal where the result of
computation process in cell body will be delivered to another
neuron.
By Doaa El-Shahat
12
Artificial neuron model
By Doaa El-Shahat
13
Artificial neuron model
Suppose that there are n input signals
(I1,I2,I3,…, In) to a neuron. Each input
signal has a weight (w1,w2,w3,…,wn).
Weights determines strength of
connections between neurons. It
can amplify or deamplify the
input signal.
if wj>1
amplify input signal
if wj<1
deamplify input signal
neuron
14
Artificial neuron model
The summing junction of artificial
neuron computes the weighted sum
of input signals (net input). (similar
to the function of dendrites and
soma).
Net input= uj =
𝐧
𝐣=𝟏 𝐈𝐣 × 𝑾𝒋+
b
To obtain the output signal of a
neuron, the net input is passed as
input to the activation function:
Output=Oj=f(uj)
neuron
15
Activation function
To better understand the role of the activation function, let
us assume a person is performing some work. To make
the work more efficient and to obtain exact output, some
force or activation may be given.
The activation function (transfer function) is used to
transfer the net input into output signal.
It decides whether the neuron can be activated or not
based on a threshold value.
There are various types of activation function that can be
used.
By Doaa El-Shahat
16
Activation function (cont.)
Identity function (linear)
It is a linear function and
can be defined as:
𝒇(𝒙) = 𝒙 𝒇𝒐𝒓 𝒂𝒍𝒍 𝒙
The output remains as the
same as input.
Binary step function
converts the net input
into binary ouput 1 or 0.
𝜽 is a threshold value
𝒇 𝒙 =
𝟏 𝒊𝒇 𝒙 ≥ 𝜽
𝟎 𝒊𝒇 𝒙 < 𝜽
Bipolar step function
converts the net input
into bipolar ouput 1 or -1.
𝜽 is a threshold value
𝒇 𝒙 =
𝟏 𝒊𝒇 𝒙 ≥ 𝜽
−𝟏 𝒊𝒇 𝒙 < 𝜽
17
Activation function (cont.)
Binary sigmoid function
converts the net input into ouput
in [0,1]. 𝝀 is a steepness (slope)
parameter to obtain sigmoid
functions of different slopes.
𝟏
𝑓 𝒙 =
𝟏 + 𝒆−𝝀𝒙
Bipolar sigmoid function
converts the net input into
ouput in [-1,1]. 𝝀 is a slope
parameter
−𝝀𝒙
𝒇 𝒙 =
𝟐
𝟏−𝒆
−
𝟏
=
𝟏 + 𝒆−𝝀𝒙
𝟏 + 𝒆−𝝀𝒙
Ramp function
maps the net input to
output over a range (0,1).
𝟏
𝒊𝒇 𝒙 > 𝟏
𝒇 𝒙 = 𝒙 𝒊𝒇 𝟎 ≤ 𝒙 ≤ 𝟏
𝟎
𝒊𝒇 𝒙 < 𝟎
18
Sigmoid function with varying slope
𝜆 = 0.5
𝜆=1
𝜆=2
By Doaa El-Shahat
19
Example 1
By Doaa El-Shahat
20
Solution to Example 1
By Doaa El-Shahat
21
Example 2
By Doaa El-Shahat
22
Solution to Example 2
By Doaa El-Shahat
23
Example 3
By Doaa El-Shahat
24
Solution to Example 3
By Doaa El-Shahat
25
Solution to Example 3
By Doaa El-Shahat
26
Example 4
By Doaa El-Shahat
27
Example 5
By Doaa El-Shahat
28
Bias
Bias allows you to shift the net input by adding a constant (i.e., the given
bias) to the input.
It is somehow similar to the constant b of a linear function
y = ax + b y=I1 W1+b
With b, we can shift the line to fit the prediction with the data better.
Without b, the line always goes through the origin (0, 0) and you may get a
poorer fit which is not in accordance with real-world scenario.
Y=ax
Y=ax+b
29
Bias
Bias plays a major role in determining the output of the network.
The bias can be of two types: positive bias and negative bias.
The positive bias helps in increasing the net input of the network.
The negative bias helps in decreasing the net input of the network.
Thus, as a result of the bias effect, the output of the network can be varied.
By Doaa El-Shahat
30
Bias
Given I1=1, w1=2, I2=2, w2=2. Compute net input.
Net input=I1×W1+I2×W2=1×2+2×2=6
Suppose after applying activation function the output
becomes 1.To control the output, we can add the bias,
suppose b=-6.
Net input=I1×W1+I2×W2+b=1×2+2×2+(-6)=0
Suppose after applying activation function the output
becomes 0.
By Doaa El-Shahat
31
Layer of neurons
Layer of neurons contains n
input signals(I1, I2, . . . , In)
connected to this layer of
neurons through the weights
[W ].
By Doaa El-Shahat
32
Types of layers in ANN
•
An Input Layer that takes as input the
raw data and passes them to the rest of
the network.
•
One or more Hidden Layers that are
intermediate layers between the input
and output layer and process the data by
applying complex non-linear functions to
them.
•
An Output Layer that takes as input the
processed data and produces the final
results.
By Doaa El-Shahat
33
Multiple layers of neurons
By Doaa El-Shahat
34
ANN usages
By Doaa El-Shahat
35
Regressoin
Regression: is a statistical method that determines
relationship between independent variable to dependent
variable to obtain fitted function according to data.
The purpose of using ANN for Regression over Linear
Regression is that the linear regression can only learn the
linear relationship between the features and target and
therefore cannot learn the complex non-linear
relationship.
36
• Regression estimates the relationship between
a target outcome label and one or more feature
variables to predict a continuous numeric value.
In the simple example below linear regression is
variables to predict a continuous numeric value.
• In the simple example below linear regression is
used to estimate the house price (the label)
based on the house size (the feature).
By Doaa El-Shahat
37
By Doaa El-Shahat
38
Regressoin (cont.)
ANNs can learn the complex relationship between the features and target
due to the presence of non-linear activation function in each layer.
Best fitting, linear regression
Poor fitting, non-linear
regression
By Doaa El-Shahat
Good fitting, non-linear
regression
39
Classification
Classification predict class of input data according to target or data label.
By Doaa El-Shahat
40
Clustering
Clustering is the task of grouping set of objects that are similar in the same
cluster or group without data label or target.
By Doaa El-Shahat
41
Forecasting
Forecasting: predict future condition using present and
past data or known as time series data.
By Doaa El-Shahat
42
Artificial neuron Learning
Is there an approach for determining the values of the
weights 𝑾𝒊 and threshold 𝜽?
It is easy to calculate the values of 𝑊𝑖 and 𝜃 for simple
problems.
But suppose that no prior knowledge exists except for data.
How can 𝑊𝑖 and 𝜃 values be computed? Through learning.
The AN learns the best values for the 𝑊𝑖 and 𝜃 from the
given data.
By Doaa El-Shahat
43
Learning
Learning consists of adjusting weight and threshold values
until a certain criterion (or several criteria) is (are)
satisfied.
There are three main types of learning:
1. Supervised learning.
2. Unsupervised learning.
3. Reinforcement learning.
44
Supervised learning
The neuron (or NN) is provided with a data set
consisting of input and desired output. This data
set is referred to as the training set.
The aim of supervised training is then to adjust
the weight values such that the error between
the output o = f(net−θ), of the neuron and the
desired output is minimized.
Develop predictive model based on input and
output data.
By Doaa El-Shahat
45
Supervised learning
• Supervised machine learning, also called
predictive analytics, uses algorithms to train
a model to find patterns in a dataset with
labels and features.
• It then uses the trained model to predict
the labels on a new dataset’s features.
• Supervised learning can be further
categorized
into
classification
and
regression.
By Doaa El-Shahat
46
Supervised learning
By Doaa El-Shahat
47
By Doaa El-Shahat
48
Unsupervised learning
Unsupervised learning, where the aim is to discover patterns
or features in the input data with no assistance from an
external source.
No idea which types of results are expected, such as clustering
and dimensionality reduction.
Unsupervised learning doesn’t have labeled data provided in
advance, and can aid data scientists in finding previously
unknown patterns in data. These algorithms attempt to ‘learn’
the inherent structure in the input data, discovering
similarities, or regularities. Common unsupervised tasks
include clustering
andEl-Shahat
association.
By Doaa
49
Unsupervised learning
In clustering, an algorithm classifies inputs
into categories by analyzing similarities
between input examples.
An example of clustering is a company that
wants to segment its customers in order to
better tailor products and offerings.
Customers could be grouped on features such
as demographics and purchase histories.
By Doaa El-Shahat
50
By Doaa El-Shahat
51
Reinforcement learning
There are no training data sets.
An example of reinforcemnent learning problem is playing
game.
where the aim is to reward the neuron (or parts of a NN)
for good performance, and to penalize the neuron for bad
performance.
Several learning rules have been developed for the
different learning types. Before continuing with these
learning rules, we simplify our AN model by introducing
augmented vectors.
By Doaa El-Shahat
52
Learning
By Doaa El-Shahat
53
Drawbacks of neural networks
By Doaa El-Shahat
54
1. High Computational Cost
• Explanation: Training ANNs requires massive
computational power, especially for large datasets
or deep architectures (e.g., CNNs, transformers).
• Example: Training GPT-3 (a large language model)
costs millions of dollars in computing resources.
• Impact: Limits accessibility for individuals/small
organizations without access to GPUs/TPUs.
•
By Doaa El-Shahat
55
2. Need for Large Datasets
• Explanation: ANNs often require vast
amounts of labeled data to generalize well.
• Example: Image recognition models like
ResNet need millions of labeled images
(e.g., ImageNet).
• Impact: Collecting and annotating data is
time-consuming and expensive.
By Doaa El-Shahat
56
3-Overfitting
• Explanation: ANNs may memorize
noise/patterns in training data instead of
learning generalizable features.
• Example: A model trained to classify
cats/dogs fails on new images because it
overfits to background colors.
• Solution: Regularization (e.g., dropout,
weight decay) or cross-validation.
By Doaa El-Shahat
57
When to Avoid ANNs?
• Small datasets.
• Real-time applications with limited
computational resources
By Doaa El-Shahat
58
Optimization
1
Optimization is the process of finding
the best solution out of all feasible
solutions.
Optimization
The aim of optimization is to find an
algorithm which solves a given class of
problems.
There exists no specific method which
solves effectively all optimization
problems (No free launch theorems).
2
Classification of optimization
problems
1. Depending on the nature of equations involved in the
objective function and constraints:
Linear optimization problem
Non-linear optimization problem
3
Linear optimization problem
An optimization problem is called linear, if both the
objective function as well as all the constraints are found
to be linear functions of design variables.
Maximize:
y = f(x1, x2) = 2x1 + x2
subject to:
x1 + x2 ≤ 3,
5x1 + 2x2 ≤ 10.
and
x1, x2 ≥ 0.
4
-> objetive function
-> constraint
->bounds of a variable
Non-linear optimization problem
An optimization problem is called non-linear, if any one or
both of the objective function and the constraints are
found to be non-linear functions of design variables.
Maximize:
y = f(x1, x2) =x12 + x23
subject to:
x14 + x22 ≤ 629,
x13 + x23 ≤ 133,
and
x1, x2 ≥ 0.
5
Classification of optimization problems
(cont.)
2. Based on the existence of any functional constraint:
Un constrained optimization problem.
Constrained optimization problem.
6
Un constrained vs constrained
optimization problem
The unconstrained optimization problem does not contain
any functional constraints, such as:
Minimize: y = f(x1, x2) = (x1 − 5)2 + (x2 − 1)2
and x1, x2 ≥ 0.
The constrained optimization problem contains at least one
functional constraint, such as:
Minimize: y = f(x1, x2) = (x1 − 5)2 + (x2 − 1)2
Subject to: x1 − 5 x2 < 50.
and x1, x2 ≥ 0.
7
Classification of optimization problems
(cont.)
3. Depending on the type of design variables:
Integer programming optimization problem.
Real-valued programming optimization problem.
Mixed integer programming optimization problem.
8
Integer programming problem
An optimization problem is said to be an integer
programming problem, if all the design variables take only
integer values.
Maximize y = f(x1, x2) = 2x1 + x2
subject to
x1 + x2 ≤ 3,
5x1 + 2x2 ≤ 9.
and
x1, x2 ≥ 0,
x1, x2 are integers.
9
Real-valued programming problem
An optimization problem is said to be real-valued
programming problem, if all the design variables take only
real values.
Maximize y = f(x1, x2) = 2x1 + x2
subject to
x1 + x2 ≤ 3.2,
5x1 + 2x2 ≤ 9.5.
and
x1, x2 ≥ 0.0,
x1, x2 are real values.
10
Mixed programming problem
An optimization problem is said to be an mixed
programming problem, if some of the design variables take
integer values and the remaining design variables take
real values.
Maximize y = f(x1, x2) = 2x1 + x2
subject to
x1 + x2 ≤ 3.2,
5x1 + 2x2 ≤ 9.5.
and
X1>3, x2 ≥ 0.0,
x1 is integer and x2 real values.
11
Single objective vs multi-objective
optimization problem
4. Depending on the number of objective functions:
Single optimization problem.
Multi-objective optimization problem.
Single optimization problem is a problem that contains only
one objective function to be optimized (maximized or
minimized).
Multi-objective optimization problem is a problem that has
a set or vector of conflicting objective functions to be
optimized.
12
Combinatorial vs continuous
optimization problem
13
▪
Combinatorial or discrete optimization problem is an
optimization problem in which its design variables takes
discrete values.
▪
Continuous optimization problem is an optimization
problem in which its design variables takes continuous
values.
Optimization methods
1. Exact method
Advantage: it can guarantee to find the accurate and
optimal solution, such as dynamic programming, branchand-bound, and integer linear programming.
Disadvantage: in the worst case, if the problem size is
increased, the time complexity would be increased
exponentially.
It is suitable for small- scale optimization problems.
2. Approximate method
It can not guarantee to find the accurate solution.
It obtains approximate solutions in an acceptable and
reasonable time.
It is suitable for large-scale optimization problems.
14
Heuristic method
It is an approximate method designed to solve quickly the
problem, while scarifying the exact solution.
They are often problem-dependent, that is, you define a
heuristic for a given problem.
The quality of solution depends on the initial starting
points.
15
Knapsack problem
Knapsack problem is difficult to solve in large scale.
Exact methods may take thousands of years (NP-hard ).
0-1 Knapscak problem (cont.)
0-1 KP contains a set of 𝑛 items. Each item 𝑖 has a weight
𝑤𝑖 and a profit 𝑝𝑖 .
Objective function: maximize profit of the selected items in the
knapsack.
Constraint: The sum of weights of packed items must not
exceed the knapsack capacity 𝑐. Each item can be selected once
or not (𝑥𝑖 = 1 𝑜𝑟 𝑥𝑖 = 0).
𝑛
𝑀𝑎𝑥
𝑖=1 𝑝𝑖 𝑥𝑖
0−1 𝐾𝑃 𝑆. 𝑡. 𝑛𝑖=1 𝑤𝑖 𝑥𝑖 ≤ c
𝑥𝑖 ∈ 0,1
Fractional knapsack problems(cont.)
In 0-1 knapsack problems, each item is selected or not to be in
put in the knapsack with nor fractions.
In fractional knapsack problem, we can take fraction of an item
such that the total weights of all items can’t exceed the
capacity of the knapsack.
Solved example using greedy algorithm
•
•
Knapsack Capacity: 15 kg
Items (Weight, Value):
• Item 1: 2 kg, $10
• Item 2: 5 kg, $20
• Item 3: 10 kg, $30
• Item 4: 5 kg, $16
• Item 5: 3 kg, $18
1. Calculate Value-to-Weight Ratios:
▪
1
10/2=5$
▪
2
20/5=4$
▪
3
30/10=3$
▪
4
16/5=3.2$
▪
5
18/3=6$
2. Sort Items by Value/kg (Descending):
Item 5 → Item 1 → Item 2 → Item 4 → Item 3.
19
Greedy algorithm for 0-1 KP
•
•
1. Calculate Value-to-Weight Ratios:
Knapsack Capacity: 16 kg
▪ 1 10/2=5$
Items (Weight, Value):
▪ 2 20/5=4$
• Item 1: 2 kg, $10
▪ 3 30/10=3$
• Item 2: 5 kg, $20
▪ 4 16/5=3.2$
• Item 3: 10 kg, $30
▪ 5 18/3=6$
• Item 4: 5 kg, $16
• Item 5: 3 kg, $18
2. Sort Items by Value/kg (Descending):
Item 5 → Item 1 → Item 2 → Item 4 → Item 3.
20
• Total weight=3 + 2 + 5 + 5=15Kg
• Total value=18+ 10+20+16=64$
• Items:
5, 1, 2, 4, stop as fractions can’t be allowed
Greedy algorithm for fractional KP
•
•
1. Calculate Value-to-Weight Ratios:
Knapsack Capacity: 16 kg
▪ 1 10/2=5$
Items (Weight, Value):
▪ 2 20/5=4$
• Item 1: 2 kg, $10
▪ 3 30/10=3$
• Item 2: 5 kg, $20
▪ 4 16/5=3.2$
• Item 3: 10 kg, $30
▪ 5 18/3=6$
• Item 4: 5 kg, $16
• Item 5: 3 kg, $18
2. Sort Items by Value/kg (Descending):
Item 5 → Item 1 → Item 2 → Item 4 → Item 3.
21
• Total weight=3 + 2 + 5 + 5+1=16 Kg
• Total value=18+ 10+20+16+6=70$ optimal
• Items:
5, 1, 2, 4, 1/10 of item 3
Knapsack problem (cont.)
Example of knapsack problem
Example of knapsack problem
Item no.
Weight
Profit
1
2
3
4
5
12
1
4
1
2
4
2
10
1
2
Problem Statement
▪
▪
▪
25
Knapsack Capacity: 15 kg
Items Available:
▫ Item 1: Weight = 10 kg, Value = $60
▫ Item 2: Weight = 20 kg, Value = $100
▫ Item 3: Weight = 30 kg, Value = $120
Goal: Maximize the total value without
exceeding the knapsack capacity (fractions
allowed).
Solution Using Greedy Algorithm
▪ Step 1: Calculate Value-to-Weight Ratio
Sort items by value per kilogram (descending order):
▪
▪
▪
▪
Item 1: 60/10 = 6$
Item 2: 100/20 = 5$
Item 3: 120/30 = 4$
Sorted Order: Item 1 → Item 2 → Item 3
▪ Step 2: Fill the Knapsack Greedily
▪ Take Item 1 (10 kg):
▫ Remaining Capacity: 15−10=5 kg15−10=5kg
▫ Value Added: $60
▪ Take Fraction of Item 2 (5 kg):
▫ Item 2’s total weight = 20 kg, but only 5 kg needed.
▫ Fraction Taken: 520=0.25205=0.25
▫ Value Added: 0.25×100=$250.25×100=$25
▫ Remaining Capacity: 5−5=0 kg5−5=0kg
▪ Item 3 is skipped (no remaining capacity).
Final Result
▪ Total Value: $60+$25=$85
▪ Total Weight: 10 kg+5 kg=15 kg10kg+5kg=15kg
▪
Explanation
The greedy algorithm prioritizes items with
the highest value per unit weight. By taking all
of Item 1 and a fraction of Item 2, we maximize
the total value without exceeding the knapsack’s
capacity. This approach guarantees an optimal
solution for the fractional knapsack problem.
28
29
Example for 0-1 Knapsack (Greedy Fails ❌ ) Problem:
▪
▪
30
Capacity: 50 kg
Items:
▫ Item A: Weight = 10 kg, Value = $60
▫ Item B: Weight = 20 kg, Value = $100
▫ Item C: Weight = 30 kg, Value = $120
31
Fill the knapsack greedily:
Take Item A (10 kg → $60).
Take Item B (20 kg → $100).
Total weight = 10+20=30 kg10+20=30kg,
remaining capacity = 20 kg.
Item C (30 kg) cannot fit.
Total Value: $60+$100=$160$60+$100=$160.
Example of asymmetric TSP (permutation problem)
Distance matrix
Dij
1
2
3
4
5
6
7
1
0
10
15
20
2
8
7
2
8
0
5
21
22
11
9
3
5
19
0
13
19
5
3
4
23
25
17
0
16
3
13
5
26
9
10
17
0
14
18
6
2
12
18
15
4
0
24
7
13
10
3
11
19
26
0
2. Fitness function
No.
1
2
3
4
5
6
7
8
9
10
position X Fitness= 𝑫𝒊𝒋
1523476
1352764
7341526
6425137
5143762
3241576
4315267
2153746
5273461
4156723
2+9+5+13+13+26+2=70
15+19+9+9+26+15+23=116
3+13+23+2+9+11+24=85
15+25+22+26+15+3+26=132
26+20+17+3+26+12+22=126
19+21+23+2+18+26+18=127
17+5+2+9+11+24+11=79
8+2+10+3+11+3+12=49
9+9+3+13+3+2+2=41
23+2+14+24+10+5+13=91
Dij
1
2
3
4
5
6
7
1
0
10
15
20
2
8
7
2
8
0
5
21
22
11
9
3
5
19
0
13
19
5
3
4
23
25
17
0
16
3
13
5
26
9
10
17
0
14
18
6
2
12
18
15
4
0
24
7
13
10
3
11
19
26
0
TSP example
34
Metaheuristic algorithm
Metaheuristics are approximate methods that can not
guarantee the exact and optimal solutions.
They are problem-independent techniques that can be
applied to a broad range of problems.
For example, genetic algorithm and particle swarm
algorithms are metaheuristic algorithms.
35
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )