0% found this document useful (0 votes)
44 views35 pages

A I Notes

Notes

Uploaded by

ramdas.kprabhu74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views35 pages

A I Notes

Notes

Uploaded by

ramdas.kprabhu74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Here, one of the booming technologies of computer science is

Artificial Intelligence Artificial Intelligence which is ready to create a new revolution in the
world by making intelligent machines. The Artificial Intelligence is
Unit I: now all around us. It is currently working with a variety of subfields,
ranging from general to specific, such as self-driving cars, playing
Introduction- What is Artificial Intelligence, Foundations of AI, chess, proving theorems, playing music, Painting, etc.
History, AI - Past, Present and Future. Intelligent Agents-
Environments- Specifying the task environment, Properties of task AI is one of the fascinating and universal fields of Computer science
environments, Agent based programs-Structure of Agents, Types of which has a great scope in future. AI holds a tendency to cause a
agents-Simple reflex agents, Model-based reflex agents, Goal-based machine to work as a human.
agents; and Utility-based agents.

Artificial Intelligence is composed of two


Unit II:
words Artificial and Intelligence, where Artificial defines "man-
made," and intelligence defines "thinking power", hence AI means "a man-
Problem Solving by Searching-Problem-Solving Agents, Well-
made thinking power."
defined problems and solutions, examples Problems, Searching for
Solutions, Uninformed Search Strategies-Breadth-first search, So, we can define AI as:
Uniform-cost search, Depth-first search, Depth-limited search,
Iterative deepening depth-first search, Bidirectional search, Greedy "It is a branch of computer science by which we can create intelligent
best-first search, A*Search, AO*search Informed(Heuristic) Search machines which can behave like a human, think like humans, and able to
Strategies, Heuristic Functions. make decisions."

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Artificial Intelligence exists when a machine can have human based
skills such as learning, reasoning, and solving problems

What is Artificial Intelligence? With Artificial Intelligence you do not need to pre-program a
machine to do some work, despite that you can create a machine
In today's world, technology is growing very fast, and we are getting with programmed algorithms which can work with own intelligence,
in touch with different new technologies day by day. and that is the awesomeness of AI.
Artificial Intelligence Notes Page No: 1
It is believed that AI is not a new technology, and some people says o Playing chess
that as per Greek myth, there were Mechanical men in early days o Plan some surgical operation
which can work and behave like humans. o Driving a car in traffic
5. Creating some system which can exhibit intelligent behavior, learn
new things by itself, demonstrate, explain, and can advise to its user.
Why Artificial Intelligence?

Before Learning about Artificial Intelligence, we should know that What Comprises to Artificial Intelligence?
what is the importance of AI and why should we learn it. Following
Artificial Intelligence is not just a part of computer science even it's
are some main reasons to learn about AI:
so vast and requires lots of other factors which can contribute to it.
o With the help of AI, you can create such software or devices which To create the AI first we should know that how intelligence is
can solve real-world problems very easily and with accuracy such as health composed, so the Intelligence is an intangible part of our brain which
issues, marketing, traffic issues, etc. is a combination of Reasoning, learning, problem-solving
o With the help of AI, you can create your personal virtual Assistant, perception, language understanding, etc.
such as Cortana, Google Assistant, Siri, etc.
o With the help of AI, you can build such Robots which can work in an To achieve the above factors for a machine or software Artificial
environment where survival of humans can be at risk. Intelligence requires the following discipline:
o AI opens a path for other new technologies, new devices, and new
Opportunities. o Mathematics
o Biology
Goals of Artificial Intelligence o Psychology
o Sociology
Following are the main goals of Artificial Intelligence: o Computer Science
o Neurons Study
1. Replicate human intelligence o Statistics
2. Solve Knowledge-intensive tasks
3. An intelligent connection of perception and action
4. Building a machine which can perform tasks that requires human
intelligence such as:
o Proving a theorem
Artificial Intelligence Notes Page No: 2
o Useful as a public utility: AI can be very useful for public utilities
such as a self-driving car which can make our journey safer and hassle-free,
facial recognition for security purpose, Natural language processing to
communicate with the human in human-language, etc.

Disadvantages of Artificial Intelligence

Every technology has some disadvantages, and the same goes for
Artificial intelligence. Being so advantageous technology still, it has
some disadvantages which we need to keep in our mind while
creating an AI system. Following are the disadvantages of AI:
Advantages of Artificial Intelligence
o High Cost: The hardware and software requirement of AI is very
Following are some main advantages of Artificial Intelligence: costly as it requires lots of maintenance to meet current world
requirements.
o High Accuracy with less errors: AI machines or systems are prone o Can't think out of the box: Even we are making smarter machines
to less errors and high accuracy as it takes decisions as per pre-experience with AI, but still they cannot work out of the box, as the robot will only do
or information. that work for which they are trained, or programmed.
o High-Speed: AI systems can be of very high-speed and fast- o No feelings and emotions: AI machines can be an outstanding
decision making, because of that AI systems can beat a chess champion in performer, but still it does not have the feeling so it cannot make any kind
the Chess game. of emotional attachment with human, and may sometime be harmful for
o High reliability: AI machines are highly reliable and can perform users if the proper care is not taken.
the same action multiple times with high accuracy. o Increase dependency on machines: With the increment of
o Useful for risky areas: AI machines can be helpful in situations such technology, people are getting more dependent on devices and hence they
as defusing a bomb, exploring the ocean floor, where to employ a human are losing their mental capabilities.
can be risky. o No Original Creativity: As humans are so creative and can imagine
o Digital Assistant: AI can be very useful to provide digital assistant some new ideas but still AI machines cannot beat this power of human
to the users such as AI technology is currently used by various E-commerce intelligence and cannot be creative and imaginative.
websites to show the products as per customer requirement.

What are Agent and Environment?


Artificial Intelligence Notes Page No: 3
An AI system is composed of an agent and its environment. The  Performance Measure of Agent − It is the criteria, which
agents act in their environment. The environment may contain other determines how successful an agent is.
agents.  Behavior of Agent − It is the action that agent performs after
any given sequence of percepts.
An agent is anything that can perceive its environment  Percept − It is agent’s perceptual inputs at a given instance.
through sensors and acts upon that environment through effectors.  Percept Sequence − It is the history of all that an agent has
perceived till date.
 A human agent has sensory organs such as eyes, ears, nose,
 Agent Function − It is a map from the precept sequence to
tongue and skin parallel to the sensors, and other organs such as
an action.
hands, legs, mouth, for effectors.
 A robotic agent replaces cameras and infrared range finders
Rationality
for the sensors, and various motors and actuators for effectors.
 A software agent has encoded bit strings as its programs and
Rationality is nothing but status of being reasonable, sensible, and
actions.
having good sense of judgment.

Rationality is concerned with expected actions and results depending


upon what the agent has perceived. Performing actions with the aim
of obtaining useful information is an important part of rationality.

What is Ideal Rational Agent?

An ideal rational agent is the one, which is capable of doing expected


actions to maximize its performance measure, on the basis of −

 Its percept sequence


 Its built-in knowledge base
Agent Terminology
Rationality of an agent depends on the following −

Artificial Intelligence Notes Page No: 4


 The performance measures, which determine the degree of  Autonomous robots: These are agents that are designed to
success. operate autonomously in the physical world. They can perform tasks
 Agent’s Percept Sequence till now. such as cleaning, sorting, and delivering goods. Examples of
 The agent’s prior knowledge about the environment. autonomous robots include the Roomba vacuum cleaner and the
 The actions that the agent can carry out. Amazon delivery robot.
 Gaming agents: These are agents that are designed to play
A rational agent always performs right action, where the right action games, either against human opponents or other agents. Examples
means the action that causes the agent to be most successful in the of gaming agents include chess-playing agents and poker-playing
given percept sequence. The problem the agent solves is agents.
characterized by Performance Measure, Environment, Actuators, and  Fraud detection agents: These are agents that are designed
Sensors (PEAS). to detect fraudulent behavior in financial transactions. They can
analyze patterns of behavior to identify suspicious activity and alert
The Structure of Intelligent Agents authorities. Examples of fraud detection agents include those used
by banks and credit card companies.
Agent’s structure can be viewed as −
 Traffic management agents: These are agents that are
 Agent = Architecture + Agent Program designed to manage traffic flow in cities. They can monitor traffic
 Architecture = the machinery that an agent executes on. patterns, adjust traffic lights, and reroute vehicles to minimize
 Agent Program = an implementation of an agent function. congestion. Examples of traffic management agents include those
used in smart cities around the world.
There are many examples of agents in artificial intelligence. Here are  A software agent has Keystrokes, file contents, received
a few: network packages that act as sensors and displays on the screen,
files, and sent network packets acting as actuators.
 Intelligent personal assistants: These are agents that are  A Human-agent has eyes, ears, and other organs which act
designed to help users with various tasks, such as scheduling as sensors, and hands, legs, mouth, and other body parts act as
appointments, sending messages, and setting reminders. Examples actuators.
of intelligent personal assistants include Siri, Alexa, and Google  A Robotic agent has Cameras and infrared range finders
Assistant. which act as sensors and various motors act as actuators.

Artificial Intelligence Notes Page No: 5


Simple Reflex Agents

Simple reflex agents ignore the rest of the percept history and act
only on the basis of the current percept. Percept history is the
history of all that an agent has perceived to date. The agent function
is based on the condition-action rule. A condition-action rule is a
rule that maps a state i.e., a condition to an action. If the condition
is true, then the action is taken, else not. This agent function only
succeeds when the environment is fully observable. For simple reflex
agents operating in partially observable environments, infinite loops
are often unavoidable. It may be possible to escape from infinite
loops if the agent can randomize its actions.

Problems with Simple reflex agents are :

Types of Agents  Very limited intelligence.


 No knowledge of non-perceptual parts of the state.
Agents can be grouped into five classes based on their degree of  Usually too big to generate and store.
perceived intelligence and capability:  If there occurs any change in the environment, then the
collection of rules needs to be updated.
 Simple Reflex Agents
 Model-Based Reflex Agents
 Goal-Based Agents
 Utility-Based Agents
 Learning Agent
 Multi-agent systems
 Hierarchical agents

Artificial Intelligence Notes Page No: 6


 How the world evolves independently from the agent?
 How do the agent’s actions affect the world?

Simple Reflex Agents

Example: A Simple Reflex Agent is typically employed when all the


information of the current game state is directly observable,
(eg: Chess, Checkers, Tic Tac Toe, Connect-Four) and the decision
regarding the move only depends on the current state.
Model-Based Reflex Agents

Model-Based Reflex Agents Example: Self-driving cars are a great example of a model-based
reflex agent. The car is equipped with sensors that detect obstacles,
It works by finding a rule whose condition matches the current such as car brake lights in front of them or pedestrians walking on
situation. A model-based agent can handle partially observable the sidewalk. As it drives, these sensors feed percepts into the car's
environments by the use of a model about the world. The agent memory and internal model of its environment.
has to keep track of the internal state which is adjusted by each
percept and that depends on the percept history. The current state Goal-Based Agents
is stored inside the agent which maintains some kind of structure
describing the part of the world which cannot be seen. These kinds of agents take decisions based on how far they are
currently from their goal(description of desirable situations). Their
Updating the state requires information about: every action is intended to reduce their distance from the goal. This
Artificial Intelligence Notes Page No: 7
allows the agent a way to choose among multiple possibilities, Utility-Based Agents
selecting the one which reaches a goal state. The knowledge that
supports its decisions is represented explicitly and can be modified, The agents which are developed having their end uses as building
which makes these agents more flexible. They usually require search blocks are called utility-based agents. When there are multiple
and planning. The goal-based agent’s behavior can easily be possible alternatives, then to decide which one is best, utility-based
changed. agents are used. They choose actions based on a preference
(utility) for each state. Sometimes achieving the desired goal is not
enough. We may look for a quicker, safer, cheaper trip to reach a
destination. Agent happiness should be taken into consideration.
Utility describes how “happy” the agent is. Because of the
uncertainty in the world, a utility agent chooses the action that
maximizes the expected utility. A utility function maps a state onto
a real number which describes the associated degree of happiness.

Goal-Based Agents

Example: Google's Waymo driverless cars are good examples of a


goal-based agent when they are programmed with an end
destination, or goal, in mind. The car will then ''think'' and make the
right decisions in order to deliver the passenger where they intended
to go.

Artificial Intelligence Notes Page No: 8


Utility-Based Agents

Example: A reflex agent, for example, could be a home thermostat


that knows to start heating or cooling your house based on reaching
a certain temperature.

Learning Agent

A learning agent in AI is the type of agent that can learn from its
past experiences or it has learning capabilities. It starts to act with
basic knowledge and then is able to act and adapt automatically
through learning. A learning agent has mainly four conceptual
components, which are:

1. Learning element: It is responsible for making


improvements by learning from the environment.
Learning Agent
2. Critic: The learning element takes feedback from critics
which describes how well the agent is doing with respect to a fixed
Multi-Agent Systems
performance standard.
3. Performance element: It is responsible for selecting external These agents interact with other agents to achieve a common goal.
action. They may have to coordinate their actions and communicate with
4. Problem Generator: This component is responsible for each other to achieve their objective.
suggesting actions that will lead to new and informative
experiences. A multi-agent system (MAS) is a system composed of multiple
interacting agents that are designed to work together to achieve a
common goal. These agents may be autonomous or semi-
autonomous and are capable of perceiving their environment,

Artificial Intelligence Notes Page No: 9


making decisions, and taking action to achieve the common their behavior. Machine learning is used to train agents to improve
objective. their decision-making capabilities over time. Agent-based modeling
is used to simulate complex systems and study the interactions
MAS can be used in a variety of applications, including between agents.
transportation systems, robotics, and social networks. They can help
improve efficiency, reduce costs, and increase flexibility in complex Overall, multi-agent systems are a powerful tool in artificial
systems. MAS can be classified into different types based on their intelligence that can help solve complex problems and improve
characteristics, such as whether the agents have the same or efficiency in a variety of applications.
different goals, whether the agents are cooperative or competitive,
and whether the agents are homogeneous or heterogeneous. Hierarchical Agents

 In a homogeneous MAS, all the agents have the same These agents are organized into a hierarchy, with high-level agents
capabilities, goals, and behaviors. overseeing the behavior of lower-level agents. The high-level
 In contrast, in a heterogeneous MAS, the agents have agents provide goals and constraints, while the low-level agents
different capabilities, goals, and behaviors. carry out specific tasks. Hierarchical agents are useful in complex
environments with many tasks and sub-tasks.
This can make coordination more challenging but can also lead to
more flexible and robust systems.  Hierarchical agents are agents that are organized into a
hierarchy, with high-level agents overseeing the behavior of lower-
Cooperative MAS involves agents working together to achieve a
level agents. The high-level agents provide goals and constraints,
common goal, while competitive MAS involves agents working
while the low-level agents carry out specific tasks. This structure
against each other to achieve their own goals. In some cases, MAS
allows for more efficient and organized decision-making in complex
can also involve both cooperative and competitive behavior, where
environments.
agents must balance their own interests with the interests of the
 Hierarchical agents can be implemented in a variety of
group.
applications, including robotics, manufacturing, and transportation
systems. They are particularly useful in environments where there
MAS can be implemented using different techniques, such as game
are many tasks and sub-tasks that need to be coordinated and
theory, machine learning, and agent-based modeling. Game theory
prioritized.
is used to analyze strategic interactions between agents and predict
Artificial Intelligence Notes Page No: 10
 In a hierarchical agent system, the high-level agents are Uses of Agents
responsible for setting goals and constraints for the lower-level
agents. These goals and constraints are typically based on the Agents are used in a wide range of applications in artificial
overall objective of the system. For example, in a manufacturing intelligence, including:
system, the high-level agents might set production targets for the
lower-level agents based on customer demand.  Robotics: Agents can be used to control robots and
 The low-level agents are responsible for carrying out specific automate tasks in manufacturing, transportation, and other
tasks to achieve the goals set by the high-level agents. These tasks industries.
may be relatively simple or more complex, depending on the  Smart homes and buildings: Agents can be used to control
specific application. For example, in a transportation system, low- heating, lighting, and other systems in smart homes and buildings,
level agents might be responsible for managing traffic flow at optimizing energy use and improving comfort.
specific intersections.  Transportation systems: Agents can be used to manage
 Hierarchical agents can be organized into different levels, traffic flow, optimize routes for autonomous vehicles, and improve
depending on the complexity of the system. In a simple system, logistics and supply chain management.
there may be only two levels: high-level agents and low-level  Healthcare: Agents can be used to monitor patients, provide
agents. In a more complex system, there may be multiple levels, with personalized treatment plans, and optimize healthcare resource
intermediate-level agents responsible for coordinating the activities allocation.
of lower-level agents.  Finance: Agents can be used for automated trading, fraud
 One advantage of hierarchical agents is that they allow for detection, and risk management in the financial industry.
more efficient use of resources. By organizing agents into a  Games: Agents can be used to create intelligent opponents
hierarchy, it is possible to allocate tasks to the agents that are best in games and simulations, providing a more challenging and
suited to carry them out, while avoiding duplication of effort. This realistic experience for players.
can lead to faster, more efficient decision-making and better overall  Natural language processing: Agents can be used for
performance of the system. language translation, question answering, and chatbots that can
communicate with users in natural language.
Overall, hierarchical agents are a powerful tool in artificial  Cybersecurity: Agents can be used for intrusion detection,
intelligence that can help solve complex problems and improve malware analysis, and network security.
efficiency in a variety of applications.

Artificial Intelligence Notes Page No: 11


 Environmental monitoring: Agents can be used to monitor Turing Test
and manage natural resources, track climate change, and improve
environmental sustainability. The success of an intelligent behavior of a system can be measured
 Social media: Agents can be used to analyze social media with Turing Test.
data, identify trends and patterns, and provide personalized
Two persons and a machine to be evaluated participate in the test.
recommendations to users.
Out of the two persons, one plays the role of the tester. Each of them
sits in different rooms. The tester is unaware of who is machine and
The Nature of Environments
who is a human. He interrogates the questions by typing and sending
Some programs operate in the entirely artificial them to both intelligences, to which he receives typed responses.
environment confined to keyboard input, database, computer file
This test aims at fooling the tester. If the tester fails to determine
systems and character output on a screen.
machine’s response from the human response, then the machine is
In contrast, some software agents (software robots or softbots) exist said to be intelligent.
in rich, unlimited softbots domains. The simulator has a very
detailed, complex environment. The software agent needs to
Properties of Environment
choose from a long array of actions in real time. A softbot designed
The environment has multifold properties −
to scan the online preferences of the customer and show interesting
items to the customer works in the real as well as  Discrete / Continuous − If there are a limited number of
an artificial environment. distinct, clearly defined, states of the environment, the environment
is discrete (For example, chess); otherwise it is continuous (For
The most famous artificial environment is the Turing Test
example, driving).
environment, in which one real and other artificial agents are tested
 Observable / Partially Observable − If it is possible to
on equal ground. This is a very challenging environment as it is highly
determine the complete state of the environment at each time point
difficult for a software agent to perform as well as a human.
from the percepts it is observable; otherwise it is only partially
observable.
 Static / Dynamic − If the environment does not change while
an agent is acting, then it is static; otherwise it is dynamic.

Artificial Intelligence Notes Page No: 12


 Single agent / Multiple agents − The environment may
contain other agents which may be of the same or different kind as
that of the agent.
 Accessible / Inaccessible − If the agent’s sensory apparatus
can have access to the complete state of the environment, then the
environment is accessible to that agent.
 Deterministic / Non-deterministic − If the next state of the
environment is completely determined by the current state and the
actions of the agent, then the environment is deterministic; otherwise
it is non-deterministic.
 Episodic / Non-episodic − In an episodic environment, each
episode consists of the agent perceiving and then acting. The quality
of its action depends just on the episode itself. Subsequent episodes
do not depend on the actions in the previous episodes. Episodic Search Algorithms in Artificial Intelligence
environments are much simpler because the agent does not need to
think ahead. Search algorithms are one of the most important areas of Artificial
Intelligence. This topic will explain all about the search algorithms in
Artificial Intelligence - Research Areas AI.

The domain of artificial intelligence is huge in breadth and width. Problem-solving agents:
While proceeding, we consider the broadly common and
prospering research areas in the domain of AI – In Artificial Intelligence, Search techniques are universal problem-
solving methods. Rational agents or Problem-solving agents in AI
mostly used these search strategies or algorithms to solve a specific
problem and provide the best result. Problem-solving agents are the
goal-based agents and use atomic representation. In this topic, we
will learn various problem-solving search algorithms.

Artificial Intelligence Notes Page No: 13


Search Algorithm Terminologies: Completeness: A search algorithm is said to be complete if it
guarantees to return a solution if at least any solution exists for any
o Search: Searchingis a step by step procedure to solve a random input.
search-problem in a given search space. A search problem can have
Optimality: If a solution found for an algorithm is guaranteed to be
three main factors:
the best solution (lowest path cost) among all other solutions, then
a. Search Space: Search space represents a set of possible
such a solution for is said to be an optimal solution.
solutions, which a system may have.
b. Start State: It is a state from where agent begins the search.
Time Complexity: Time complexity is a measure of time for an
c. Goal test: It is a function which observe the current state and
algorithm to complete its task.
returns whether the goal state is achieved or not.
o Search tree: A tree representation of search problem is called Space Complexity: It is the maximum storage space required at any
Search tree. The root of the search tree is the root node which is point during the search, as the complexity of the problem.
corresponding to the initial state.
o Actions: It gives the description of all the available actions to Types of search algorithms
the agent.
o Transition model: A description of what each action do, can Based on the search problems we can classify the search
be represented as a transition model. algorithms into uninformed (Blind search) search and informed
o Path Cost: It is a function which assigns a numeric cost to each search (Heuristic search) algorithms.
path.
o Solution: It is an action sequence which leads from the start
node to the goal node.
o Optimal Solution: If a solution has the lowest cost among all
solutions.

Properties of Search Algorithms:

Following are the four essential properties of search algorithms to


compare the efficiency of these algorithms:
Artificial Intelligence Notes Page No: 14
o Breadth-first search
o Uniform cost search
o Depth-first search
o Iterative deepening depth-first search
o Bidirectional Search

Informed Search

Informed search algorithms use domain knowledge. In an informed


search, problem information is available which can guide the search.
Informed search strategies can find a solution more efficiently than
an uninformed search strategy. Informed search is also called a
Heuristic search.

A heuristic is a way which might not always be guaranteed for best


solutions but guaranteed to find a good solution in reasonable time.
Uninformed/Blind Search:
Informed search can solve much complex problem which could not
The uninformed search does not contain any domain knowledge
be solved in another way.
such as closeness, the location of the goal. It operates in a brute-
force way as it only includes information about how to traverse the An example of informed search algorithms is a traveling salesman
tree and how to identify leaf and goal nodes. Uninformed search problem.
applies a way in which search tree is searched without any
information about the search space like initial state operators and 1. Greedy Search
test for the goal, so it is also called blind search. It examines each 2. A* Search
node of the tree until it achieves the goal node.
Uninformed Search Algorithms
It can be divided into five main types:

Artificial Intelligence Notes Page No: 15


Uninformed search is a class of general-purpose search o BFS will provide a solution if any solution exists.
algorithms which operates in brute force-way. Uninformed o If there are more than one solutions for a given problem, then BFS
search algorithms do not have additional information about will provide the minimal solution which requires the least number of steps.

state or search space other than how to traverse the tree, so it is


Disadvantages:
also called blind search.
o It requires lots of memory since each level of the tree must be
Following are the various types of uninformed search
saved into memory to expand the next level.
algorithms:
o BFS needs lots of time if the solution is far away from the root
1. Breadth-first Search node.
2. Depth-first Search
3. Depth-limited Search Example:
4. Iterative deepening depth-first search
5. Uniform cost search In the below tree structure, we have shown the traversing of the tree
6. Bidirectional Search using BFS algorithm from the root node S to goal node K. BFS search
algorithm traverse in layers, so it will follow the path which is shown
1. Breadth-first Search: by the dotted arrow, and the traversed path will be:

o Breadth-first search is the most common search strategy for 1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I----
traversing a tree or graph. This algorithm searches breadthwise in a tree or >K
graph, so it is called breadth-first search.
o BFS algorithm starts searching from the root node of the tree and
expands all successor node at the current level before moving to nodes of
next level.
o The breadth-first search algorithm is an example of a general-graph
search algorithm.
o Breadth-first search implemented using FIFO queue data structure.

Advantages:

Artificial Intelligence Notes Page No: 16


2. Depth-first Search

o Depth-first search isa recursive algorithm for traversing a tree


or graph data structure.
o It is called the depth-first search because it starts from the root
node and follows each path to its greatest depth node before moving
to the next path.
o DFS uses a stack data structure for its implementation.
o The process of the DFS algorithm is similar to the BFS
algorithm.

Note: Backtracking is an algorithm technique for finding all possible


solutions using recursion.
Time Complexity: Time Complexity of BFS algorithm can be
obtained by the number of nodes traversed in BFS until the Advantage:
shallowest Node. Where the d= depth of shallowest solution and b
o DFS requires very less memory as it only needs to store a stack
is a node at every state.
of the nodes on the path from root node to the current node.
T (b) = 1+b2+b3+.......+ bd= O (bd) o It takes less time to reach to the goal node than BFS algorithm
(if it traverses in the right path).
Space Complexity: Space complexity of BFS algorithm is given by
the Memory size of frontier which is O(bd). Disadvantage:

Completeness: BFS is complete, which means if the shallowest goal o There is the possibility that many states keep re-occurring, and
node is at some finite depth, then BFS will find a solution. there is no guarantee of finding the solution.
o DFS algorithm goes for deep down searching and sometime it
Optimality: BFS is optimal if path cost is a non-decreasing function may go to the infinite loop.
of the depth of the node.
Example:
Artificial Intelligence Notes Page No: 17
In the below search tree, we have shown the flow of depth-first It requires lots of memory since each level of the tree must be saved
search, and it will follow the order as: into memory to expand the next level.

Root node--->Left node ----> right node. o BFS needs lots of time if the solution is far away from the root
node.
It will start searching from root node S, and traverse A, then B, then
D and E, after traversing E, it will backtrack the tree as E has no other Example:
successor and still goal node is not found. After backtracking it will
traverse node C and then G, and here it will terminate as it found goal In the below tree structure, we have shown the traversing of the tree
node. using BFS algorithm from the root node S to goal node K. BFS search
algorithm traverse in layers, so it will follow the path which is shown
by the dotted arrow, and the traversed path will be:

1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I----
>K

Completeness: DFS search algorithm is complete within finite state


space as it will expand every node within a limited search tree.

Time Complexity: Time complexity of DFS will be equivalent to the


node traversed by the algorithm. It is given by:

Artificial Intelligence Notes Page No: 18


Time Complexity: Time Complexity of BFS algorithm can be Advantage:
obtained by the number of nodes traversed in BFS until the
shallowest Node. Where the d= depth of shallowest solution and b o DFS requires very less memory as it only needs to store a stack
is a node at every state. of the nodes on the path from root node to the current node.
o It takes less time to reach to the goal node than BFS algorithm
2 3 d d
T (b) = 1+b +b +.......+ b = O (b ) (if it traverses in the right path).

Space Complexity: Space complexity of BFS algorithm is given by Disadvantage:


d
the Memory size of frontier which is O(b ).
o There is the possibility that many states keep re-occurring, and
Completeness: BFS is complete, which means if the shallowest goal there is no guarantee of finding the solution.
node is at some finite depth, then BFS will find a solution. o DFS algorithm goes for deep down searching and sometime it
may go to the infinite loop.
Optimality: BFS is optimal if path cost is a non-decreasing function
of the depth of the node. Example:

2. Depth-first Search In the below search tree, we have shown the flow of depth-first
search, and it will follow the order as:
o Depth-first search isa recursive algorithm for traversing a tree
or graph data structure. Root node--->Left node ----> right node.
o It is called the depth-first search because it starts from the root
node and follows each path to its greatest depth node before moving It will start searching from root node S, and traverse A, then B, then
to the next path. D and E, after traversing E, it will backtrack the tree as E has no other
o DFS uses a stack data structure for its implementation. successor and still goal node is not found. After backtracking it will
o The process of the DFS algorithm is similar to the BFS traverse node C and then G, and here it will terminate as it found goal
algorithm. node.

Note: Backtracking is an algorithm technique for finding all possible


solutions using recursion.

Artificial Intelligence Notes Page No: 19


3. Depth-Limited Search Algorithm:

A depth-limited search algorithm is similar to depth-first search with


a predetermined limit. Depth-limited search can solve the drawback
of the infinite path in the Depth-first search. In this algorithm, the
node at the depth limit will treat as it has no successor nodes further.

Depth-limited search can be terminated with two Conditions of


failure:

o Standard failure value: It indicates that problem does not have


any solution.
Completeness: DFS search algorithm is complete within finite state o Cutoff failure value: It defines no solution for the problem
space as it will expand every node within a limited search tree. within a given depth limit.

Time Complexity: Time complexity of DFS will be equivalent to the Advantages:


node traversed by the algorithm. It is given by:
Depth-limited search is Memory efficient.
2 3 m m
T(n)= 1+ n + n +.........+ n =O(n )
Disadvantages:
Where, m= maximum depth of any node and this can be much
larger than d (Shallowest solution depth) o Depth-limited search also has a disadvantage of
incompleteness.
Space Complexity: DFS algorithm needs to store only single path o It may not be optimal if the problem has more than one
from the root node, hence space complexity of DFS is equivalent to solution.
the size of the fringe set, which is O(bm).
Example:
Optimal: DFS search algorithm is non-optimal, as it may generate a
large number of steps or high cost to reach to the goal node.

Artificial Intelligence Notes Page No: 20


according to their path costs form the root node. It can be used to
solve any graph/tree where the optimal cost is in demand. A uniform-
cost search algorithm is implemented by the priority queue. It gives
maximum priority to the lowest cumulative cost. Uniform cost search
is equivalent to BFS algorithm if the path cost of all edges is the same.

Advantages:

o Uniform cost search is optimal because at every state the path


with the least cost is chosen.

Disadvantages:
Completeness: DLS search algorithm is complete if the solution is
above the depth-limit. o It does not care about the number of steps involve in
searching and only concerned about path cost. Due to which this

Time Complexity: Time complexity of DLS algorithm is O(b ). algorithm may be stuck in an infinite loop.

Space Complexity: Space complexity of DLS algorithm is O(b×ℓ). Example:


Optimal: Depth-limited search can be viewed as a special case of
DFS, and it is also not optimal even if ℓ>d.

4. Uniform-cost Search Algorithm:

Uniform-cost search is a searching algorithm used for traversing a


weighted tree or graph. This algorithm comes into play when a
different cost is available for each edge. The primary goal of the
uniform-cost search is to find a path to the goal node which has the
lowest cumulative cost. Uniform-cost search expands nodes

Artificial Intelligence Notes Page No: 21


The same logic is for space complexity so, the worst-case space
complexity of Uniform-cost search is O(b1 + [C*/ε]).

Optimal:

Uniform-cost search is always optimal as it only selects a path with


the lowest path cost.

5. Iterative deepening depth-first Search:

The iterative deepening algorithm is a combination of DFS and BFS


algorithms. This search algorithm finds out the best depth limit and
does it by gradually increasing the limit until a goal is found.

Completeness: This algorithm performs depth-first search up to a certain "depth


limit", and it keeps increasing the depth limit after each iteration until
Uniform-cost search is complete, such as if there is a solution, UCS
the goal node is found.
will find it.

This Search algorithm combines the benefits of Breadth-first search's


Time Complexity:
fast search and depth-first search's memory efficiency.
Let C* is Cost of the optimal solution, and ε is each step to get
The iterative search algorithm is useful uninformed search when
closer to the goal node. Then the number of steps is = C*/ε+1. Here
search space is large, and depth of goal node is unknown.
we have taken +1, as we start from state 0 and end to C*/ε.

Advantages:
Hence, the worst-case time complexity of Uniform-cost search is
O(b1 + [C*/ε])/. o It combines the benefits of BFS and DFS search algorithm in
terms of fast search and memory efficiency.
Space Complexity:

Disadvantages:
Artificial Intelligence Notes Page No: 22
o The main drawback of IDDFS is that it repeats all the work of Completeness:
the previous phase.
This algorithm is complete is if the branching factor is finite.
Example:
Time Complexity:

Following tree structure is showing the iterative deepening depth-


Let's suppose b is the branching factor and depth is d then the worst-
first search. IDDFS algorithm performs various iterations until it does
case time complexity is O(bd).
not find the goal node. The iteration performed by the algorithm is
given as: Space Complexity:

The space complexity of IDDFS will be O(bd).

Optimal:

IDDFS algorithm is optimal if path cost is a non- decreasing function


of the depth of the node.

6. Bidirectional Search Algorithm:

Bidirectional search algorithm runs two simultaneous searches, one


form initial state called as forward-search and other from goal node
called as backward-search, to find the goal node. Bidirectional search
replaces one single search graph with two small sub graphs in which
1'st Iteration-----> A one starts the search from an initial vertex and other starts from goal
2'nd Iteration----> A, B, C vertex. The search stops when these two graphs intersect each other.
3'rd Iteration------>A, B, D, E, C, F, G
Bidirectional search can use search techniques such as BFS, DFS, DLS,
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
etc.
In the fourth iteration, the algorithm will find the goal node.

Artificial Intelligence Notes Page No: 23


Advantages:

o Bidirectional search is fast.


o Bidirectional search requires less memory

Disadvantages:

o Implementation of the bidirectional search tree is difficult.


o In bidirectional search, one should know the goal state in
advance.

Example:

In the below search tree, bidirectional search algorithm is applied. Completeness: Bidirectional Search is complete if we use BFS in both
This algorithm divides one graph/tree into two sub-graphs. It starts searches.
traversing from node 1 in the forward direction and starts from goal
node 16 in the backward direction. Time Complexity: Time complexity of bidirectional search using BFS
is O(bd).
The algorithm terminates at node 9 where two searches meet.
Space Complexity: Space complexity of bidirectional search is O(bd).

Optimal: Bidirectional search is Optimal.

Artificial Intelligence Notes Page No: 24


Informed Search Algorithms Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence
heuristic cost should be less than or equal to the estimated cost.
So far we have talked about the uninformed search algorithms which
looked through search space for all possible solutions of the problem Pure Heuristic Search:
without having any additional knowledge about search space. But
informed search algorithm contains an array of knowledge such as Pure heuristic search is the simplest form of heuristic search
how far we are from the goal, path cost, how to reach to goal node, algorithms. It expands nodes based on their heuristic value h(n). It
etc. This knowledge help agents to explore less to the search space maintains two lists, OPEN and CLOSED list. In the CLOSED list, it
and find more efficiently the goal node. places those nodes which have already expanded and in the OPEN
list, it places nodes which have yet not been expanded.
The informed search algorithm is more useful for large search space.
Informed search algorithm uses the idea of heuristic, so it is also On each iteration, each node n with the lowest heuristic value is
called Heuristic search. expanded and generates all its successors and n is placed to the
closed list. The algorithm continues unit a goal state is found.
Heuristics function: Heuristic is a function which is used in Informed
Search, and it finds the most promising path. It takes the current state In the informed search we will discuss two main algorithms which are
of the agent as its input and produces the estimation of how close given below:
agent is from the goal. The heuristic method, however, might not
o Best First Search Algorithm(Greedy search)
always give the best solution, but it guaranteed to find a good
o A* Search Algorithm
solution in reasonable time. Heuristic function estimates how close a
state is to the goal. It is represented by h(n), and it calculates the cost
1.) Best-first Search Algorithm (Greedy Search):
of an optimal path between the pair of states. The value of the
heuristic function is always positive.
Greedy best-first search algorithm always selects the path which
appears best at that moment. It is the combination of depth-first
Admissibility of the heuristic function is given as:
search and breadth-first search algorithms. It uses the heuristic
1. h(n) <= h*(n) function and search. Best-first search allows us to take the
advantages of both algorithms. With the help of best-first search, at
each step, we can choose the most promising node. In the best first
Artificial Intelligence Notes Page No: 25
search algorithm, we expand the node which is closest to the goal o Best first search can switch between BFS and DFS by gaining
node and the closest cost is estimated by heuristic function, i.e. the advantages of both the algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
1. f(n)= g(n).
Disadvantages:
Were, h(n)= estimated cost from node n to the goal.

o It can behave as an unguided depth-first search in the worst


The greedy best first algorithm is implemented by the priority queue.
case scenario.
It can get stuck in a loop as DFS.
Best first search algorithm:
o
o This algorithm is not optimal.
o Step 1: Place the starting node into the OPEN list.
o Step 2: If the OPEN list is empty, Stop and return failure. Example:
o Step 3: Remove the node n, from the OPEN list which has the
Consider the below search problem, and we will traverse it using
lowest value of h(n), and places it in the CLOSED list.
greedy best-first search. At each iteration, each node is expanded
o Step 4: Expand the node n, and generate the successors of
using evaluation function f(n)=h(n) , which is given in the below table.
node n.
o Step 5: Check each successor of node n, and find whether any
node is a goal node or not. If any successor node is goal node, then
return success and terminate the search, else proceed to Step 6.
o Step 6: For each successor node, algorithm checks for
evaluation function f(n), and then check if the node has been in either
OPEN or CLOSED list. If the node has not been in both list, then add
it to the OPEN list.
o Step 7: Return to Step 2.

Advantages:

Artificial Intelligence Notes Page No: 26


Expand the nodes of S and put in the CLOSED list

Initialization: Open [A, B], Closed [S]

Iteration 1: Open [A], Closed [S, B]

Iteration 2: Open [E, F, A], Closed [S, B]


: Open [E, A], Closed [S, B, F]

Iteration 3: Open [I, G, E, A], Closed [S, B, F]


: Open [I, E, A], Closed [S, B, F, G]

Hence the final solution path will be: S----> B----->F----> G

Time Complexity: The worst case time complexity of Greedy best


In this search example, we are using two lists which
first search is O(bm).
are OPEN and CLOSED Lists. Following are the iteration for traversing the
above example.
Space Complexity: The worst case space complexity of Greedy best
first search is O(bm). Where, m is the maximum depth of the search
space.

Complete: Greedy best-first search is also incomplete, even if the


given state space is finite.

Optimal: Greedy best first search algorithm is not optimal.

2.) A* Search Algorithm:

A* search is the most commonly known form of best-first search. It


uses heuristic function h(n), and cost to reach the node n from the

Artificial Intelligence Notes Page No: 27


start state g(n). It has combined features of UCS and greedy best-first Step 3: Select the node from the OPEN list which has the smallest
search, by which it solve the problem efficiently. A* search algorithm value of evaluation function (g+h), if node n is goal node then return
finds the shortest path through the search space using the heuristic success and stop, otherwise
function. This search algorithm expands less search tree and provides
optimal result faster. A* algorithm is similar to UCS except that it uses Step 4: Expand node n and generate all of its successors, and put n
g(n)+h(n) instead of g(n). into the closed list. For each successor n', check whether n' is already
in the OPEN or CLOSED list, if not then compute evaluation function
In A* search algorithm, we use search heuristic as well as the cost to for n' and place into Open list.
reach the node. Hence we can combine both costs as following, and
this sum is called as a fitness number. Step 5: Else if node n' is already in OPEN and CLOSED, then it should
be attached to the back pointer which reflects the lowest g(n') value.

Step 6: Return to Step 2.

Advantages:

o A* search algorithm is the best algorithm than other search


At each point in the search space, only those node is expanded which algorithms.
have the lowest value of f(n), and the algorithm terminates when the o A* search algorithm is optimal and complete.
goal node is found. o This algorithm can solve very complex problems.

Algorithm of A* search: Disadvantages:

Step1: Place the starting node in the OPEN list. o It does not always produce the shortest path as it mostly
based on heuristics and approximation.
Step 2: Check if the OPEN list is empty or not, if the list is empty then o A* search algorithm has some complexity issues.
return failure and stops. o The main drawback of A* is memory requirement as it keeps
all generated nodes in the memory, so it is not practical for various
large-scale problems.
Artificial Intelligence Notes Page No: 28
Example:

In this example, we will traverse the given graph using the A*


algorithm. The heuristic value of all states is given in the below table
so we will calculate the f(n) of each state using the formula f(n)=
g(n) + h(n), where g(n) is the cost to reach any node from start
state.

Here we will use OPEN and CLOSED list.

Initialization: {(S, 5)}

Iteration1: {(S--> A, 4), (S-->G, 10)}

Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}

Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A--


>B, 7), (S-->G, 10)}

Solution: Iteration 4 will give the final result, as S--->A--->C--->G it provides


the optimal path with cost 6.

Points to remember:

o A* algorithm returns the path which occurred first, and it does


not search for all remaining paths.

Artificial Intelligence Notes Page No: 29


The efficiency of A* algorithm depends on the quality of
o
heuristic.
AO* algorithm – Artificial intelligence
o A* algorithm expands all nodes which satisfy the condition
Best-first search is what the AO* algorithm does. The AO*
f(n)<="" li="">
method divides any given difficult problem into a smaller
group of problems that are then resolved using the AND-
Complete: A* algorithm is complete as long as:
OR graph concept. AND OR graphs are specialized graphs that are
o Branching factor is finite. used in problems that can be divided into smaller problems. The
o Cost at every action is fixed. AND side of the graph represents a set of tasks that must be
completed to achieve the main goal, while the OR side of the graph
Optimal: A* search algorithm is optimal if it follows below two represents different methods for accomplishing the same main
conditions: goal.

o Admissible: the first condition requires for optimality is that


h(n) should be an admissible heuristic for A* tree search. An
admissible heuristic is optimistic in nature.
o Consistency: Second required condition is consistency for
only A* graph-search.

If the heuristic function is admissible, then A* tree search will always


find the least cost path.

Time Complexity: The time complexity of A* search algorithm


depends on heuristic function, and the number of nodes expanded
is exponential to the depth of solution d. So the time complexity is
O(b^d), where b is the branching factor.
AND-OR Graph
Space Complexity: The space complexity of A* search algorithm
is O(b^d) In the above figure, the buying of a car may be broken down into
smaller problems or tasks that can be accomplished to achieve the
Artificial Intelligence Notes Page No: 30
main goal in the above figure, which is an example of a simple  A* algorithm and AO* algorithm both works on the best
AND-OR graph. The other task is to either steal a car that will help first search.
us accomplish the main goal or use your own money to purchase a  They are both informed search and works on given
car that will accomplish the main goal. The AND symbol is used to heuristics values.
indicate the AND part of the graphs, which refers to the need that  A* always gives the optimal solution but AO* doesn’t
all sub problems containing the AND to be resolved before the guarantee to give the optimal solution.
preceding node or issue may be finished.  Once AO* got a solution doesn’t explore all possible paths
but A* explores all paths.
The start state and the target state are already known in the  When compared to the A* algorithm, the AO* algorithm
knowledge-based search strategy known as the AO* algorithm, uses less memory.
and the best path is identified by heuristics. The informed search  Opposite to the A* algorithm, the AO* algorithm cannot go
technique considerably reduces the algorithm’s time complexity. into an endless loop.
The AO* algorithm is far more effective in searching AND-OR
trees than the A* algorithm. Example:

Working of AO* algorithm:

The evaluation function in AO* looks like this:


f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.

Difference between the A* Algorithm and AO*


algorithm

Artificial Intelligence Notes Page No: 31


Step 1

AO* Algorithm – Question tree


AO* Algorithm (Step-1)
Here in the above example below the Node which is given is the
heuristic value i.e h(n). Edge length is considered as 1. With help of f(n) = g(n) + h(n) evaluation function,

Start from node A,

f(A⇢B) = g(B) + h(B)

=1 + 5 ……here g(n)=1 is taken by default for


path cost

=6

Artificial Intelligence Notes Page No: 32


f(A⇢C+D) = g(c) + h(c) + g(d) + h(d) Here the value of E & F are calculated as follows,

=1+2+1+4 ……here we have added C & D


because they are in AND
f(B⇢E) = g(e) + h(e)
=8
f(B⇢E) = 1 + 7
So, by calculation A⇢B path is chosen which is the minimum
path, i.e f(A⇢B) =8

Step 2
f(B⇢f) = g(f) + h(f)

f(B⇢f) = 1 + 9

= 10

So, by above calculation B⇢E path is chosen which is minimum


path, i.e f(B⇢E)

because B's heuristic value is different from its actual value The
heuristic is

updated and the minimum cost path is selected. The


minimum value in our situation is 8.

Therefore, the heuristic for A must be updated due to the change


AO* Algorithm (Step-2) in B's heuristic.

According to the answer of step 1, explore node B So we need to calculate it again.


Artificial Intelligence Notes Page No: 33
Now explore f(A⇢C+D)

f(A⇢B) = g(B) + updated h(B) So, the current node is C

=1+8

=9 f(C⇢G) = g(g) + h(g)

We have Updated all values in the above tree. f(C⇢G) = 1 + 3

Step 3 =4

f(C⇢H+I) = g(h) + h(h) + g(i) + h(i)

f(C⇢H+I) = 1 + 0 + 1 + 0 ……here we have added H & I


because they are in AND

=2

f(C⇢H+I) is selected as the path with the lowest cost and the
heuristic is also left unchanged because it matches the actual cost.
Paths H & I are solved because the heuristic for those paths is 0,

AO* Algorithm (Step-3)


but Path A⇢D needs to be calculated because it has an AND.
By comparing f(A⇢B) & f(A⇢C+D)

f(A⇢C+D) is shown to be smaller. i.e 8 < 9


Artificial Intelligence Notes Page No: 34
f(D⇢J) = g(j) + h(j)

f(D⇢J) = 1 + 0

=1

the heuristic of node D needs to be updated to 1.

f(A⇢C+D) = g(c) + h(c) + g(d) + h(d)

=1+2+1+1

=5

as we can see that path f(A⇢C+D) is get solved and this tree has
become a solved tree now.

In simple words, the main flow of this algorithm is that we have to


find firstly level 1st heuristic value and then level 2nd and after
that update the values with going upward means towards the
root node.

********

Artificial Intelligence Notes Page No: 35

You might also like