0% found this document useful (0 votes)
92 views89 pages

Unit 1 Ai PDF

Uploaded by

rishiparmar921
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)
92 views89 pages

Unit 1 Ai PDF

Uploaded by

rishiparmar921
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/ 89

ARTIFICIAL

INTELLIGENCE
Introduction to AI
 Artificial intelligence refers to the simulation of
human intelligence in machines that are
programmed to think like humans and mimic their
actions.
 Artificial intelligence (AI) is a wide-ranging branch
of computer science concerned with building
smart machines capable of performing tasks that
typically require human intelligence.
Types of AI
Types of AI
AI type-1: Based on Capabilities
 1. Weak AI or Narrow AI:
• Narrow AI is a type of AI which is able to perform a dedicated task with
intelligence. The most common and currently available AI is Narrow AI in the
world of Artificial Intelligence.
• Narrow AI cannot perform beyond its field or limitations, as it is only trained
for one specific task. Hence it is also termed as weak AI. Narrow AI can fail in
unpredictable ways if it goes beyond its limits.
• Apple Siri is a good example of Narrow AI, but it operates with a limited pre-
defined range of functions.
• IBM's Watson supercomputer also comes under Narrow AI, as it uses an Expert
system approach combined with Machine learning and natural language
processing.
• Some Examples of Narrow AI are playing chess, purchasing suggestions on e-
commerce site, self-driving cars, speech recognition, and image recognition.
Types of AI
 2. General AI:
• General AI is a type of intelligence which could perform any intellectual task
with efficiency like a human.
• The idea behind the general AI to make such a system which could be smarter
and think like a human by its own.
• Currently, there is no such system exist which could come under general AI and
can perform any task as perfect as a human.
• The worldwide researchers are now focused on developing machines with
General AI.
• As systems with general AI are still under research, and it will take lots of efforts
and time to develop such systems.
 3. Super AI:
• Super AI is a level of Intelligence of Systems at which machines could surpass
human intelligence, and can perform any task better than human with cognitive
properties. It is an outcome of general AI.
• Some key characteristics of strong AI include capability include the ability to
think, to reason,solve the puzzle, make judgments, plan, learn, and
communicate by its own.
• Super AI is still a hypothetical concept of Artificial Intelligence. Development of
such systems in real is still world changing task.
Types of AI
Artificial Intelligence type-2: Based on functionality
 1. Reactive Machines
• Purely reactive machines are the most basic types of Artificial Intelligence.
• Such AI systems do not store memories or past experiences for future actions.
• These machines only focus on current scenarios and react on it as per possible
best action.
• IBM's Deep Blue system is an example of reactive machines.
• Google's AlphaGo is also an example of reactive machines.
 2. Limited Memory
• Limited memory machines can store past experiences or some data for a short
period of time.
• These machines can use stored data for a limited time period only.
• Self-driving cars are one of the best examples of Limited Memory systems.
These cars can store recent speed of nearby cars, the distance of other cars,
speed limit, and other information to navigate the road.
Types of AI
 3. Theory of Mind
• Theory of Mind AI should understand the human emotions, people, beliefs,
and be able to interact socially like humans.
• This type of AI machines are still not developed, but researchers are making
lots of efforts and improvement for developing such AI machines.
 4. Self-Awareness
• Self-awareness AI is the future of Artificial Intelligence. These machines will
be super intelligent, and will have their own consciousness, sentiments, and
self-awareness.
• These machines will be smarter than human mind.
• Self-Awareness AI does not exist in reality still and it is a hypothetical
concept.
Importance of AI
• With the help of AI, you can create such software or devices which can solve
real-world problems very easily and with accuracy such as health issues,
marketing, traffic issues, etc.
• With the help of AI, you can create your personal virtual Assistant, such as
Cortana, Google Assistant, Siri, etc.
• With the help of AI, you can build such Robots which can work in an
environment where survival of humans can be at risk.
• AI opens a path for other new technologies, new devices, and new
Opportunities.
Goals of AI
 Replicate human intelligence
 Solve Knowledge-intensive tasks
 An intelligent connection of perception and action
 Building a machine which can perform tasks that requires human intelligence
such as:
 Proving a theorem
 Playing chess
 Plan some surgical operation
 Driving a car in traffic
 Creating some system which can exhibit intelligent behavior, learn new things
by itself, demonstrate, explain, and can advise to its user.
Applications of AI
Applications of AI
 1. AI in Astronomy
• Artificial Intelligence can be very useful to solve complex universe problems. AI
technology can be helpful for understanding the universe such as how it works,
origin, etc.
 2. AI in Healthcare
• In the last, five to ten years, AI becoming more advantageous for the
healthcare industry and going to have a significant impact on this industry.
• Healthcare Industries are applying AI to make a better and faster diagnosis than
humans. AI can help doctors with diagnoses and can inform when patients are
worsening so that medical help can reach to the patient before hospitalization.
 3. AI in Gaming
• AI can be used for gaming purpose. The AI machines can play strategic games
like chess, where the machine needs to think of a large number of possible
places.
 4. AI in Finance
• AI and finance industries are the best matches for each other. The finance
industry is implementing automation, chatbot, adaptive intelligence, algorithm
trading, and machine learning into financial processes.
Applications of AI
 5. AI in Data Security
• The security of data is crucial for every company and cyber-attacks are growing very
rapidly in the digital world. AI can be used to make your data more safe and secure.
Some examples such as AEG bot, AI2 Platform, are used to determine software bug and
cyber-attacks in a better way.
 6. AI in Social Media
• Social Media sites such as Facebook, Twitter, and Snapchat contain billions of user
profiles, which need to be stored and managed in a very efficient way. AI can organize
and manage massive amounts of data. AI can analyze lots of data to identify the latest
trends, hashtag, and requirement of different users.
 7. AI in Travel & Transport
• AI is becoming highly demanding for travel industries. AI is capable of doing various
travel related works such as from making travel arrangement to suggesting the hotels,
flights, and best routes to the customers. Travel industries are using AI-powered
chatbots which can make human-like interaction with customers for better and fast
response.
 8. AI in Automotive Industry
• Some Automotive industries are using AI to provide virtual assistant to their user for
better performance. Such as Tesla has introduced TeslaBot, an intelligent virtual
assistant.
• Various Industries are currently working for developing self-driven cars which can make
your journey more safe and secure.
Applications of AI
 9. AI in Robotics:
• Artificial Intelligence has a remarkable role in Robotics. Usually, general robots are programmed
such that they can perform some repetitive task, but with the help of AI, we can create
intelligent robots which can perform tasks with their own experiences without pre-programmed.
• Humanoid Robots are best examples for AI in robotics, recently the intelligent Humanoid robot
named as Erica and Sophia has been developed which can talk and behave like humans.
 10. AI in Entertainment
• We are currently using some AI based applications in our daily life with some entertainment
services such as Netflix or Amazon. With the help of ML/AI algorithms, these services show the
recommendations for programs or shows.
 11. AI in Agriculture
• Agriculture is an area which requires various resources, labor, money, and time for best result.
Now a day's agriculture is becoming digital, and AI is emerging in this field. Agriculture is
applying AI as agriculture robotics, solid and crop monitoring, predictive analysis. AI in
agriculture can be very helpful for farmers.
 12. AI in E-commerce
• AI is providing a competitive edge to the e-commerce industry, and it is becoming more
demanding in the e-commerce business. AI is helping shoppers to discover associated products
with recommended size, color, or even brand.
 13. AI in education:
• AI can automate grading so that the tutor can have more time to teach. AI chatbot can
communicate with students as a teaching assistant.
• AI in the future can be work as a personal virtual tutor for students, which will be accessible
easily at any time and any place.
Advantages of AI
• High Accuracy with less errors: AI machines or systems are prone to less errors
and high accuracy as it takes decisions as per pre-experience or information.
• High-Speed: AI systems can be of very high-speed and fast-decision making,
because of that AI systems can beat a chess champion in the Chess game.
• High reliability: AI machines are highly reliable and can perform the same action
multiple times with high accuracy.
• Useful for risky areas: AI machines can be helpful in situations such as defusing a
bomb, exploring the ocean floor, where to employ a human can be risky.
• Digital Assistant: AI can be very useful to provide digital assistant to the users
such as AI technology is currently used by various E-commerce websites to show
the products as per customer requirement.
• 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 AI
• High Cost: The hardware and software requirement of AI is very costly as it
requires lots of maintenance to meet current world requirements.
• Can't think out of the box: Even we are making smarter machines with AI, but
still they cannot work out of the box, as the robot will only do that work for which
they are trained, or programmed.
• No feelings and emotions: AI machines can be an outstanding performer, but
still it does not have the feeling so it cannot make any kind of emotional
attachment with human, and may sometime be harmful for users if the proper
care is not taken.
• Increase dependency on machines: With the increment of technology, people
are getting more dependent on devices and hence they are losing their mental
capabilities.
• No Original Creativity: As humans are so creative and can imagine some new
ideas but still AI machines cannot beat this power of human intelligence and
cannot be creative and imaginative
Sub-fields Of Artificial Intelligence
Sub-fields Of Artificial Intelligence
 1) Machine Learning
 Machine learning is a feature of artificial intelligence that provides the computer
with the capability to automatically gather data and learn from the experience of
the problems or cases they have encountered rather than specially programmed to
perform the given task or work.
 Pattern recognition is a sub-category of machine learning. It can be described as
the automatic recognition of the blueprint from the raw data using computer
algorithms.
 The pattern recognition process includes several steps. These are explained as
follows:
 (i) Data acquisition and sensing: This includes the collection of raw data like
physical variables etc and measurement of frequency, bandwidth, resolution, etc.
The data is of two types: training data, and learning data.
 (ii) Pre-processing of input data: This includes filtering out the unwanted data
like noise from the input source and it is done through signal processing. At this
stage, the filtration of pre-existing patterns in the input data is also done for
further references.
 (iii) Feature extraction: Various algorithms are carried out like a pattern
matching algorithm to find the matching pattern as required in terms of features.
 (iv) Classification: Based on the output of algorithms carried out and various
models learned to get the matching pattern, the class is assigned to the pattern.
 (v) Post-processing: Here the final output is presented and it will be assured that
the result achieved is almost as likely to be needed.
Sub-fields Of Artificial Intelligence
Model for pattern recognition

The feature extractor will derive the features from the input raw data, like audio, image, video,
sonic, etc.
Now, the classifier will receive x as input value and will allocate different categories to the
input value like class 1, class 2 …. class C. based on the class of the data, further recognition
and analysis of the pattern are done.

Example of recognition of triangle shape through this model:


Sub-fields Of Artificial Intelligence
 2) Neural Networks
 The neural networks are the brain of artificial intelligence. They are the computer
systems which are the replica of the neural connections in the human brain. The artificial
corresponding neurons of the brain are known as the perceptron.
 The stack of various perceptron joining together makes the artificial neural networks in
the machines. Before giving a desirable output, the neural networks gain knowledge by
processing various training examples.
 Deep learning in association with the neural networks can unfold the multiple layers of
hidden data including the output layer of complex problems and is an aide for the
subfields like speech recognition, natural language processing, and computer vision, etc.
 Feedforward neural networks (FNNs) are the simplest type of ANN, with a linear flow of
information through the network. FNNs have been widely used for tasks such as image
classification, speech recognition, and natural language processing.
 Convolutional Neural Networks (CNNs) are a special type of FNNs designed specifically for
image and video recognition tasks. CNNs are able to automatically learn features from
the images, which makes them well-suited for tasks such as image classification, object
detection, and image segmentation.
 Recurrent Neural Networks (RNNs) are a type of neural networks that are able to process
sequential data, such as time series and natural language. RNNs are able to maintain an
internal state that captures information about the previous inputs, which makes them
well-suited for tasks such as speech recognition, natural language processing, and
language translation.
Sub-fields Of Artificial Intelligence
 3) Deep learning
 Deep Learning is a subset of Machine Learning that is based on artificial neural
networks (ANNs) with multiple layers, also known as deep neural networks (DNNs).
These neural networks are inspired by the structure and function of the human
brain, and they are designed to learn from large amounts of data in an
unsupervised or semi-supervised manner.
 Deep Learning models are able to automatically learn features from the data,
which makes them well-suited for tasks such as image recognition, speech
recognition, and natural language processing. The most widely used architectures
in deep learning are feedforward neural networks, convolutional neural networks
(CNNs), and recurrent neural networks (RNNs).
 4) Cognitive computing
 Cognitive computing is the use of computerized models to simulate the human
thought process in complex situations where the answers may be ambiguous and
uncertain.
 Cognitive computing is an attempt to have computers mimic the way a human
brain works. Systems used in the cognitive sciences combine data from various
sources while weighing context and conflicting evidence to suggest the best
possible answers. To achieve this, cognitive systems include self-learning
technologies that use data mining, pattern recognition and NLP to mimic human
intelligence.
Sub-fields Of Artificial Intelligence
 5) Natural Language Processing
 With this feature of artificial intelligence, computers can interpret, identify,
locate, and process human language and speech.
 The concept behind introducing this component is to make the interaction
between the machines and the human language seamless and the computers will
become capable of delivering logical responses towards human speech or query.
 The natural language processing focus on both the verbal and written section of
human languages means both active and passive modes of using algorithms.
 The Natural Language Generation (NLG) will process and decode the sentences and
words that humans used to speak (verbal communication) while the Natural
Language Understanding (NLU) will emphasize the written vocabulary to translate
the language in the text or pixels which can be understood by machines.
 The Graphical User Interfaces (GUI) based applications of the machines are the
best example of natural language processing.
Sub-fields Of Artificial Intelligence
 6) Computer Vision
 The computer vision is a very vital part of artificial intelligence as it facilitates the
computer to automatically recognize, analyze, and interpret the visual data from
the real world images and visuals by capturing and intercepting them.
 It incorporates the skills of deep learning and pattern recognition to extract the
content of images from any data given, including images or video files within PDF
document, Word document, PPT document, XL file, graphs, and pictures, etc.
 Suppose we have a complex image of a bundle of things then only seeing the image
and memorizing it is not easily possible for everyone. The computer vision can
incorporate a series of transformations to the image to extract the bit and byte
detail about it like the sharp edges of the objects, unusual design or color used,
etc.
 The application of this component is very vastly used in the healthcare industry to
analyze the health condition of the patient by using an MRI scan, X-ray, etc. Also
used in the automobile industry to deal with computer-controlled vehicles and
drones.
AI Technique
 AI Technique: AI technique is considered as a method of using knowledge.
The research in AI for the first three decades concludes that intelligence
requires knowledge. More the knowledge an individual has, the more
intelligent he is.
Few properties of knowledge are,
• It occupies large volume.
• It is not easy to describe or characterize correctly.
• It is varying in nature i.e., it is continuously changing.
 AI Technique is a manner to organize and use the knowledge efficiently in
such a way that
• It should be understood by the people who provide it.
• It should be easily modifiable to correct errors.
• It should be useful in many situations though it is incomplete or inaccurate.
Types of AI Techniques
 The three most important AI techniques are,
 1) Search: It is a way of finding solutions to the problems that cannot be
solved directly. It also acts as a framework to which direct techniques can be
applied.
 2)Use of Knowledge: It is a way of finding solutions to the complicated
problems by means of manipulating structures of the objects.
 3) Abstraction: It is a way of isolating important aspects and manipulations
from those of the unimportant ones. This eliminates confusion pertaining to
the unimportant aspects.
Agents / Intelligent Agents in AI
 An agent is anything that can be viewed as :
1. perceiving its environment through sensors and
2. acting upon that environment through actuators
Agents / Intelligent Agents in AI
Examples of agents in artificial intelligence:
• Intelligent personal assistants: These are agents that are designed to help
users with various tasks, such as scheduling appointments, sending messages,
and setting reminders. Examples of intelligent personal assistants include
Siri, Alexa, and Google Assistant.
• Autonomous robots: These are agents that are designed to operate
autonomously in the physical world. They can perform tasks such as cleaning,
sorting, and delivering goods. Examples of autonomous robots include the
Roomba vacuum cleaner and the Amazon delivery robot.
• Gaming agents: These are agents that are designed to play games, either
against human opponents or other agents. Examples of gaming agents include
chess-playing agents and poker-playing agents.
• Fraud detection agents: These are agents that are designed to detect
fraudulent behavior in financial transactions. They can analyze patterns of
behavior to identify suspicious activity and alert authorities. Examples of
fraud detection agents include those used by banks and credit card
companies.
 Traffic management agents: They can monitor traffic patterns, adjust traffic
lights, and reroute vehicles to minimize congestion. Examples of traffic
Types of Agents

• Simple Reflex Agents


• Model-Based Reflex Agents
• Goal-Based Agents
• Utility-Based Agents
• Learning Agent
1) Simple reflex agents
 Ignores 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 i.e maps 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 :
1. Very limited intelligence.
2. No knowledge of non-perceptual parts of the state.
3. Usually too big to generate and store.
4. If there occurs any change in the environment, then the collection of rules need to be updated.
1) Simple reflex agents
2) Model Based reflex agents
 It works by finding a rule whose condition matches the current situation.
 Can handle partially observable environments by the use of a model about
the world.
 The agent has to keep track of the internal state which is adjusted by each
percept and that depends on the percept history.
 The current state is stored inside the agent which maintains some kind of
structure describing the part of the world which cannot be seen.
 Updating the state requires information about :
1. how the world evolves independently from the agent, and
2. how the agent’s actions affect the world.
2) Model Based reflex agents
3) Goal-based agents

 Take decisions based on how far they are currently from their goal.
 Their every action is intended to reduce its distance from the goal.
 Choose among multiple possibilities, selecting the one which reaches a goal state.
 The knowledge that supports its decisions is represented explicitly and can be modified.
 Agents are more flexible.
 They usually require search and planning.
 The goal-based agent’s behavior can easily be changed.
3) Goal-based agents
4) Utility-based agents

 When there are multiple possible alternatives, then to decide which one is best.
 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.
 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.
4) Utility-based agents
5) 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
2. Critic: The learning element takes feedback from critics which describes how well the agent is doing
with respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action
4. Problem Generator: This component is responsible for suggesting actions that will lead to new and
informative experiences.
5) Learning Agent
State Space Search
 State Space Search is the most commonly used technique in AI for problem solving.
 State Space means the number of states a problem can go into. It is the set of all states
reachable from initial state by executing any sequence of actions.
 State space specifies the relation among various problems states thereby forming directed
network of graphs in which the nodes are states and links between nodes represent actions
 State space search is a method used widely in artificial intelligence and computer science to
find a solution to a problem by searching through the set of possible states of the problem.
 Start State – Initial state where we start solving problem
 Intermediate States – All the states between Start and Final state
 Final State – Goal state where we find final solution
 The steps of a typical state space search algorithm
State Space Search
8 puzzle without heuristics
8 puzzle with heuristics

Here heuristic is taken as no. of misplaced tiles


Properties of Search Algorithm
Water Jug Problem
 Problem: You are given two jugs, a 4-liter one and a 3-liter one. Neither has any measuring mark
on it. There is a pump that can be used to fill the jugs with water.

I. How can you get exactly 2 liter of water into the 4-liter jug.

 Solution:

 The state space for this problem can be described as the set of ordered pairs of integers (x,y)

 Where,

 X represents the quantity of water in the 4-liter jug X= 0,1,2,3,4

 Y represents the quantity of water in 3-liter jug Y=0,1,2,3

 Start State: (0,0)

 Goal State: (2,0)


Water Jug Problem
Generate production rules for the water jug problem
Rule State Process
1 (x, y) is X<4 ->(4, Y) Fill the 4-liter jug Solution for 2 ltr water in 4 ltr jug
2 (x, y) if Y<3 -> (x, 3) Fill the 3-liter jug x y Rule
3 (x, y) if x>0 -> (x-d, d) Pour some water out of the 4-liter jug. 0 0 -
4 (x, y) if Y>0 -> (x, y-d) Pour some water out of the 3-liter jug. 0 3 2
5 (x, y) if x>0 -> (0, y) Empty the 4-liter jug on the ground 3 0 9
6 (x, y) if y>0 -> (x,0) Empty the 3-liter jug on the ground 3 3 2
(x, y) if X+Y >= 4 and y>0 -> Pour water from the 3-liter jug into the 4 2 7
7
(4, y-(4-x)) 4-liter jug until the 4-liter jug is full
0 2 5
(x, y) if X+Y>=3 and x>0 -> Pour water from the 4-liter jug into the
8 2 0 9
(x-(3-y), y)) 3-liter jug until the 3-liter jug is full.
(x, y) if X+Y <=4 and y>0 -> Pour all the water from the 3-liter jug
9
(x+y, 0) into the 4-liter jug.
(x, y) if X+Y<=3 and x>0 -> Pour all the water from the 4-liter jug
10
(0, x+y) into the 3-liter jug.
Production Systems
and its characteristics,
Issues in the design of
the search programs.
Production Systems
Helps in structuring AI programs in a way that facilitates describing and performing the
search process. A production system consists of following components.
(a ) A set of production rules, which are of the form A->B. Each rule consists of left
hand side constituent that represent the current problem state and a right hand side
that represent an output state. A rule is applicable if its left hand side matches with
the current problem state.
(b) A knowledge base, which contains all the appropriate information for the
particular task. Some part of the database may be permanent while some part of this
may pertain only to the solution of the current problem.
(c) A control strategy that specifies order in which the rules will be compared to the
database of rules and a way of resolving the conflicts that arise when several rules
match simultaneously.
(d) A rule applier, which checks the capability of rule by matching the content state
with the left hand side of the rule and finds the appropriate rule from database of
rules.
Production Systems Characteristics
 Monotonic Production System: the application of a rule never prevents the later
application of another rule that could also have been applied at the time the first rule
was selected. i.e., rules are independent.
 Non-Monotonic Production system this system helps in solving problems that were
ignored. It can be executed without backtracking to initial states when an incorrect
path was taken. The non-monotonic system provides an efficient way of solving
problems.
 Partially commutative Production system: a production system with the property
that if application of a particular sequence of rules transforms state x to state y, then
allowable permutation of those rules, also transforms state x into state y. Here the
order of operation is important.
 Commutative Production system: is a production system that is both monotonic and
partially commutative. This system is used when the order of operation is not an
Monotonic Non Monotonic
important issue of consideration. It is ideal for solving problems in a situation where
changes canPartially Commutative
be reversed. Theorem Proving Robot Navigation
Not Partially Chemical Synthesis Bridge
Commutative
Issues in the design of search Programs
 Direction of Search:
Forward: Start state to Goal state
Backward: From goal state to start state.
 Selection of Applicable rules (Matching):
Look for rules to apply.
Match rules against states.
 Method to represent each node of search process
(Knowledge representations and frame problem)
difficult to represents all facts for complex problems.
Uninformed Search Algorithms
 Uninformed search is a class of general-purpose
search algorithms which operates in brute force-way.
Uninformed search algorithms do not have additional
information about state or search space other than
how to traverse the tree, so it is also called blind
search.
 Following are the various types of uninformed search
algorithms:
1. Breadth-first Search
2. Depth-first Search
Breadth First Search (BFS)
• Breadth-first search is the most common search strategy for
traversing a tree or graph. This algorithm searches breadthwise
in a tree or graph, so it is called breadth-first search.
• 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.
• The breadth-first search algorithm is an example of a general-
graph search algorithm.
• Breadth-first search implemented using FIFO queue data
structure.
Breadth First Search (BFS)
 QUEUE1 holds all the nodes that are to be processed, while QUEUE2 holds all the nodes that are
processed and deleted from QUEUE1.
 Step 1 - First, add A to queue1 and NULL to queue2.
 Step 2 - Now, delete node A from queue1 and add it into queue2. Insert all neighbors of
node A to queue1.
 Step 3 - Now, delete node B from queue1 and add it into queue2. Insert all neighbors of
node B to queue1.
 Step 4 - Now, delete node D from queue1 and add it into queue2. Insert all neighbors of
node D to queue1. The only neighbor of Node D is F since it is already inserted, so it will
not be inserted again.
 Step 5 - Delete node C from queue1 and add it into queue2. Insert all neighbors of node
C to queue1.
 Step 6 - Delete node F from queue1 and add it into queue2. Insert all neighbors of node
F to queue1. Since all the neighbors of node F are already present, we will not insert
them again.
 Step 7 - Delete node E from queue1. Since all of its neighbors have already been added,
so we will not insert them again. Now, all the nodes are visited, and the target node E is
encountered into queue2.
Breadth First Search Algorithm
 Step 1: SET STATUS = 1 (ready state) for each node in
G
 Step 2: Enqueue the starting node A and set its
STATUS = 2 (waiting state)
 Step 3: Repeat Steps 4 and 5 until QUEUE is empty
 Step 4: Dequeue a node N. Process it and set its
STATUS = 3 (processed state).
 Step 5: Enqueue all the neighbours of N that are in
the ready state (whose STATUS = 1) and set
 their STATUS = 2
 (waiting state)
 [END OF LOOP]
Step 6: EXIT
Depth First Search (DFS)
 DFS algorithm in the data structure. It is a recursive
algorithm to search all the vertices of a tree data
structure or a graph. The depth-first search (DFS)
algorithm starts with the initial node of graph G and
goes deeper until we find the goal node or the node
with no children.
 Because of the recursive nature, stack data structure
can be used to implement the DFS algorithm. The
process of implementing the DFS is similar to the BFS
algorithm.
Depth First Search (DFS)
 Step 1 - First, push H onto the stack.
 Step 2 - POP the top element from the stack, i.e., H, and print it.
Now, PUSH all the neighbors of H onto the stack that are in ready
state.
 Step 3 - POP the top element from the stack, i.e., A, and print it.
Now, PUSH all the neighbors of A onto the stack that are in ready
state.
 Step 4 - POP the top element from the stack, i.e., D, and print it.
Now, PUSH all the neighbors of D onto the stack that are in ready
state.
 Step 5 - POP the top element from the stack, i.e., F, and print it.
Now, PUSH all the neighbors of F onto the stack that are in ready
state.
 Step 6 - POP the top element from the stack, i.e., B, and print it.
Now, PUSH all the neighbors of B onto the stack that are in ready
state.
 Step 7 - POP the top element from the stack, i.e., C, and print it.
Now, PUSH all the neighbors of C onto the stack that are in ready
state.
Depth First Search Algorithm
ALGORITHM:
 Step 1: SET STATUS = 1 (ready state) for each node in
G
 Step 2: Push the starting node A on the stack and set
its STATUS = 2 (waiting state)
 Step 3: Repeat Steps 4 and 5 until STACK is empty
 Step 4: Pop the top node N. Process it and set its
STATUS = 3 (processed state)
 Step 5: Push on the stack all the neighbors of N that
are in the ready state (whose STATUS = 1) and set
their STATUS = 2 (waiting state)
 [END OF LOOP]
 Step 6: EXIT
Informed Search Algorithms
 Informed search algorithm 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.
 The informed search algorithm is more useful for large search space. Informed
search algorithm uses the idea of heuristic, so it is also called Heuristic search.
 Heuristics function: Heuristic is a function which is used in Informed Search,
and it finds the most promising path. It takes the current state of the agent as
its input and produces the estimation of how close agent is from the goal. The
heuristic method, however, might not always give the best solution, but it
guaranteed to find a good 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 of an optimal path between the pair of states. The value of
the heuristic function is always positive
 various types of informed search algorithms:
• Best First Search Algorithm(Greedy search)
• A* Search Algorithm
• AO* Search Algorithm
• Generate and Test
Best-first Search Algorithm (Greedy Search)
 Greedy best-first search algorithm always selects the path
which appears best at that moment. It is the combination of
depth-first search and breadth-first search algorithms. It uses
the heuristic 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 search algorithm, we expand
the node which is closest to the goal node and the closest
cost is estimated by heuristic function.
 f(n)= g(n).
 Were, h(n)= estimated cost from node n to the goal.
 The greedy best first algorithm is implemented by the priority
queue.
Best-first Search Algorithm (Greedy Search)

OPEN (PRIORITY QUEUE) CLOSE (QUEUE)


[S] [S]
[B,A] [S,B]
[F,E,A] [S,B,F]
[G,I,E,A] [S,B,F,G]
Best First Search Solution is S->B->F->G
Best-first Search Algorithm (Greedy Search)
ALGORITHM:
• Step 1: Place the starting node into the OPEN list.
• Step 2: If the OPEN list is empty, Stop and return failure.
• Step 3: Remove the node n, from the OPEN list which has the
lowest value of h(n), and places it in the CLOSED list.
• Step 4: Expand the node n, and generate the successors of node
n.
• 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.
• 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.
• Step 7: Return to Step 2.
A* 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
start state g(n). It has combined features of UCS and greedy best-
first search, by which it solve the problem efficiently. A* search
algorithm finds the shortest path through the search space using the
heuristic function. This search algorithm expands less search tree
and provides optimal result faster. A* algorithm is similar to UCS
except that it uses g(n)+h(n) instead of g(n).
 In A* search algorithm, we use search heuristic as well as the cost to
reach the node. Hence we can combine both costs as following, and
this sum is called as a fitness number.
A* Algorithm
A* Algorithm
ALGORITHM:
 Step1: Place the starting node in the OPEN list.
 Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
 Step 3: Select the node from the OPEN list which has the smallest value
of evaluation function (g+h), if node n is goal node then return success
and stop, otherwise
 Step 4: Expand node n and generate all of its successors, and put 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 for n' and
place into Open list.
 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.
Problem Reduction and AO* Algorithm
 A solution to a problem can be obtained by decomposing it into smaller sub-problems
using divide and conquer. Each of this sub-problem can then be solved to get its sub-
solution. These sub-solutions can then be recombined to get a solution as a whole. That is
called Problem Reduction. This method generates arc which is called as AND arcs. One
AND arc may point to any number of successor nodes, all of which must be solved for an arc
to point to a solution.
 The AO* method divides any given difficult problem into a smaller
group of problems that are then resolved using the AND-OR graph
concept. AND OR graphs are specialized graphs that are used in problems
that can be divided into smaller problems. The 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 represents different methods for
accomplishing the same main goal.

Problem Reduction and AO* Algorithm

 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 main goal in the above figure,
which is an example of a simple AND-OR graph. The other task is to either steal a
car that will help us accomplish the main goal or use your own money to purchase a
car that will accomplish the main goal. The AND symbol is used to indicate the AND
part of the graphs, which refers to the need that all subproblems containing the AND
to be resolved before the preceding node or issue may be finished.
 The start state and the target state are already known in the knowledge-based
search strategy known as the AO* algorithm, and the best path is identified by
heuristics. The informed search technique considerably reduces the algorithm’s time
complexity. The AO* algorithm is far more effective in searching AND-OR
trees than the A* algorithm.

AO* Algorithm
 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
• A* algorithm and AO* algorithm both works on the best first search.
• They are both informed search and works on given heuristics values.
• A* always gives the optimal solution but AO* doesn’t guarantee to give the optimal
solution.
• Once AO* got a solution doesn’t explore all possible paths but A* explores all paths.
• When compared to the A* algorithm, the AO* algorithm uses less memory.
• opposite to the A* algorithm, the AO* algorithm cannot go into an endless loop.
AO* Algorithm
ALGORITHM:
1. Initialize the graph to start node
2. Traverse the graph following the current path accumulating nodes that
have not yet been expanded or solved
3. Pick any of these nodes and expand it and if it has no successors call this
value FUTILITY otherwise calculate only f' for each of the successors.
4. If f' is 0 then mark the node as SOLVED
5. Change the value of f' for the newly created node to reflect its
successors by back propagation.
6. Wherever possible use the most promising routes and if a node is
marked as SOLVED then mark the parent node as SOLVED.
7. If starting node is SOLVED or value greater than FUTILITY, stop, else
repeat from 2.
AO* Algorithm
 Example

 With help of f(n) = g(n) + h(n) evaluation function,

 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.
AO* Algorithm
AO* Algorithm
Generate and Test
 Generate and Test Search is a heuristic search technique based on
Depth First Search with Backtracking which guarantees to find a
solution if done systematically and there exists a solution. In this
technique, all the solutions are generated and tested for the best
solution. It ensures that the best solution is checked against all
possible generated solutions.
 The evaluation is carried out by the heuristic function as all the
solutions are generated systematically in generate and test algorithm
but if there are some paths which are most unlikely to lead us to
result then they are not considered. The heuristic does this by ranking
all the alternatives and is often effective in doing so. Systematic
Generate and Test may prove to be ineffective while solving complex
problems. But there is a technique to improve in complex cases as
well by combining generate and test search with other techniques so
as to reduce the search space.
Generate and Test
 Algorithm
Hill Climbing
• Hill climbing algorithm is a local search algorithm which continuously
moves in the direction of increasing elevation/value to find the peak of
the mountain or best solution to the problem. It terminates when it
reaches a peak value where no neighbor has a higher value.
• Hill climbing algorithm is a technique which is used for optimizing the
mathematical problems. One of the widely discussed examples of Hill
climbing algorithm is Traveling-salesman Problem in which we need to
minimize the distance traveled by the salesman.
• It is also called greedy local search as it only looks to its good immediate
neighbor state and not beyond that.
• A node of hill climbing algorithm has two components which are state
and value.
• Hill Climbing is mostly used when a good heuristic is available.
• In this algorithm, we don't need to maintain and handle the search tree
or graph as it only keeps a single current state.
Hill Climbing
 State-space Diagram for Hill Climbing:
 The state-space landscape is a graphical representation of the hill-climbing
algorithm which is showing a graph between various states of algorithm and
Objective function/Cost.
• On Y-axis we have taken the function which can be an objective function or
cost function, and state-space on the x-axis. If the function on Y-axis is cost
then, the goal of search is to find the global minimum and local minimum. If
the function of Y-axis is Objective function, then the goal of the search is to
find the global maximum and local maximum.
Hill Climbing
 Different regions in the state space landscape
 Local Maximum: Local maximum is a state which is better than its neighbor states, but there is
also another state which is higher than it.
 Global Maximum: Global maximum is the best possible state of state space landscape. It has
the highest value of objective function.
 Current state: It is a state in a landscape diagram where an agent is currently present.
 Flat local maximum: It is a flat space in the landscape where all the neighbor states of current
states have the same value.
 Shoulder: It is a plateau region which has an uphill edge.
 Features of Hill Climbing:
• Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to move in
the search space.
• Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the
cost.
• No backtracking: It does not backtrack the search space, as it does not remember the previous
states.
Problems in Hill Climbing
 1. Local Maximum: A local maximum is a peak state in the landscape which is better than each
of its neighboring states, but there is another state also present which is higher than the local
maximum.
 Solution: Backtracking technique can be a solution of the local maximum in state space
landscape. Create a list of the promising path so that the algorithm can backtrack the search
space and explore other paths as well.

 2. Plateau: A plateau is the flat area of the search space in which all the neighbor states of the
current state contains the same value, because of this algorithm does not find any best
direction to move. A hill-climbing search might be lost in the plateau area.
 Solution: The solution for the plateau is to take big steps or very little steps while searching, to
solve the problem. Randomly select a state which is far away from the current state so it is
possible that the algorithm could find non-plateau region.
Problems in Hill Climbing
 3. Ridges: A ridge is a special form of the local maximum. It has an area which
is higher than its surrounding areas, but itself has a slope, and cannot be
reached in a single move.
 Solution: With the use of bidirectional search, or by moving in different
directions, we can improve this problem.
Types of Hill Climbing Algorithm
 1. Simple Hill Climbing:
 Simple hill climbing is the simplest way to implement a hill climbing algorithm. It only
evaluates the neighbor node state at a time and selects the first one which optimizes
current cost and set it as a current state. It only checks it's one successor state, and if it finds
better than the current state, then move else be in the same state. This algorithm has the
following features:
• Less time consuming
• Less optimal solution and the solution is not guaranteed
 2. Steepest-Ascent hill climbing:
 The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This algorithm
examines all the neighboring nodes of the current state and selects one neighbor node which is
closest to the goal state. This algorithm consumes more time as it searches for multiple
neighbors
 3. Stochastic hill climbing:
 Stochastic hill climbing does not examine for all its neighbor before moving. Rather, this search
algorithm selects one neighbor node at random and decides whether to choose it as a current
state or examine another state.
Types of Hill Climbing Algorithm
 Algorithm for Simple Hill Climbing:
• Step 1: Evaluate the initial state, if it is goal state then return success and
Stop.
• Step 2: Loop Until a solution is found or there is no new operator left to apply.
• Step 3: Select and apply an operator to the current state.
• Step 4: Check new state:
• If it is goal state, then return success and quit.
• Else if it is better than the current state then assign new state as a current
state.
• Else if not better than the current state, then return to step2.
• Step 5: Exit.
Types of Hill Climbing Algorithm
 Algorithm for Steepest-Ascent hill climbing:
• Step 1: Evaluate the initial state, if it is goal state then return success and stop, else make
current state as initial state.
• Step 2: Loop until a solution is found or the current state does not change.
• Let SUCC be a state such that any successor of the current state will be better than it.
• For each operator that applies to the current state:
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to the SUCC.
• If it is better than SUCC, then set new state as SUCC.
• If the SUCC is better than the current state, then set current state to SUCC.
• Step 5: Exit.
Constraint Satisfaction Problem (CSP)
 CSP uses a factored representation for each state: a set of variables, each of which has
a value.
 A problem is solved when each variable has a value that satisfies all the constraints in
the variable.
 A problem described this way is called a constraint satisfaction problem.
 A CSP consists of 3 components V,D and C:
• V is a set of variables {V1,V2,V3,……,Vn}.
• D is a set of domains {D1,D2,D3,……,Dn},one for each variable.
• C is a set of constraints that specify allowable combinations of values.
Here,
• Each domain Di consists of a set off allowable values for each variable Vi.
• Each constraint Ci consists of a pair (scope,rel)
where, scope is a tuple of variables that participate in the constraint and rel is a relation
that defines the values that those variables can take on.
Coloring Map/Node Problem CSP
 When coloring a map – or any other drawing consisting of distinct regions –
adjacent countries/nodes cannot have the same color. We might also want to
use as few different colors as possible.
 V ={1,2,3,4}
 D = {RED, GREEN, BLUE}
 C = {(1!=2), (1!=3), (1!=4), (2!=4), (3!=4)}

1 2 3 4
Initial Domain RED, GREEN, BLUE RED, GREEN, BLUE RED, GREEN, BLUE RED, GREEN, BLUE
1 = RED RED GREEN, BLUE GREEN, BLUE GREEN, BLUE
2 = GREEN RED GREEN GREEN, BLUE GREEN, BLUE
3 = BLUE RED GREEN BLUE EMPTY
Backtracking
3 = GREEN RED GREEN GREEN BLUE done here
Crypt Arithmetic Problem CSP
 The Crypt-Arithmetic problem in Artificial Intelligence is a type of encryption
problem in which the written message in an alphabetical form which is easily
readable and understandable is converted into a numeric form which is neither
easily readable nor understandable. In simpler words, the crypt-arithmetic
problem deals with the converting of the message from the readable plain text
to the non-readable ciphertext. The constraints which this problem follows
during the conversion is as follows:
1. A number 0-9 is assigned to a particular alphabet.
2. Each different alphabet has a unique number.
3. All the same, alphabets have the same numbers.
4. The numbers should satisfy all the operations that any normal number does.
Crypt Arithmetic Problem CSP
 Example
 We first look for the MSB in the last word which is 'M' in the word 'MONEY' here. It is the letter which is
generated by carrying. So, carry generated can be only one. SO, we have M=1.
 Now, we have S+M=O in the second column from the left side. Here M=1. Therefore, we have, S+1=O. So, we
need a number for S such that it generates a carry when added with 1. And such a number is 9. Therefore, we
have S=9 and O=0.
 Now, in the next column from the same side we have E+O=N. Here we have O=0. Which means E+0=N which is
not possible. This means a carry was generated by the lower place digits. So we have:
 1+E=N ----------(i)
 Next alphabets that we have are N+R=E -------(ii)
 So, for satisfying both equations (i) and (ii), we get E=5 and N=6.
 Now, R should be 9, but 9 is already assigned to S, So, R=8 and we have 1 as a carry which is generated from
the lower place digits.
 Now, we have D+5=Y and this should generate a carry. Therefore, D should be greater than 4. As 5, 6,
8 and 9 are already assigned, we have D=7 and therefore Y=2.
 Therefore, the solution to the given Crypt-Arithmetic problem is:
 S=9; E=5; N=6; D=7; M=1; O=0; R=8; Y=2
Missionaries and Cannibal Problem
 On one bank of a river are three missionaries and three cannibals. There is one boat available
that can hold up to two people and that they would like to use to cross the river. If the cannibals
ever outnumber the missionaries on either of the river’s banks, the missionaries will get eaten.
How can the boat be used to safely carry all the missionaries and cannibals across the river?
 Solution: Step Ending State Starting
Side Side
 State Representation : <R,M,C> <2,0,0> Initial <1,3,3>

R : River Side 1 <2,1,1> <1,2,2>


2 <2,0,1> <1,3,2>
1 : Starting
3 <2,0,3> <1,3,0>
2 : Ending 4 <2,0,2> <1,3,1>
M : Number of missionaries 5 <2,2,2> <1,1,1>
C : Number of cannibals 6 <2,1,1> <1,2,2>
7 <2,3,1> <1,0,2>
8 <2,3,0> <1,0,3>
9 <2,3,2> <1,0,1>
10 <2,3,1> <1,0,2>
11 <2,3,3> Goal <1,0,0>
Travelling Salesman Problem
 The traveling salesman problem consists of a sale person (salesman ) and a group of cities.In which salesmen
have to travel. The salesmen have to select a starting point (starting city) and then have to visit all the cities
and have to return to the starting point (where he started). So, what we want do here is minimize the total
path (length of path) or travel cost travel by salesman.
 State is represented as pair of any two cities and distance between them.
 Matrix in which the cost of going from one node (City) to another (City) is given.

A B C D
Possible Routes
A 0 20 40 22
B 20 0 13 30
C 40 13 0 12
D 22 30 12 0
Tower of Hanoi
 Tower of Hanoi is a mathematical puzzle where we have three rods (P1,P2 and P3) and 3 disks. Initially, all
the disks are stacked in decreasing value of diameter i.e., the smallest disk is placed on the top and they are
on rod P1. The objective of the puzzle is to move the entire stack to another rod (here considered P3),
obeying the following simple rules:
• Only one disk can be moved at a time.
• Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e.
a disk can only be moved if it is the uppermost disk on a stack.
• No disk may be placed on top of a smaller disk.

You might also like