Ai Unit 1 Notes
Ai Unit 1 Notes
1.1 INTRODUCTION TO AI
Intelligence:
The ability to learn and solve problems. This definition is taken from webster’s Dictionary.
The most common answer that one expects is “to make computers intelligent so that they
can act intelligently!”, but the question is how much intelligent? How can one judge
intelligence?
as intelligent as humans. If the computers can, somehow, solve real-world problems, by
improving on their own from past experiences, they would be called “intelligent”.
Thus, the AI systems are more generic(rather than specific), can “think” and are more
flexible.
Intelligence, as we know, is the ability to acquire and apply knowledge. Knowledge is the
information acquired through experience. Experience is the knowledge gained through
exposure(training). Summing the terms up, we get artificial intelligence as the “copy of
something natural(i.e., human beings) ‘WHO’ is capable of acquiring and applying the
information it has gained through exposure.”
Definition:
"It is a branch of computer science by which we can create intelligent machines which can
behave like a human, think like humans, and able to make decisions."
Reasoning
Learning
Problem-Solving
Perception
Linguistic Intelligence
1. To create expert systems that exhibit intelligent behavior with the capability to learn,
demonstrate, explain, and advise its users.
2. Helping machines find solutions to complex problems like humans do and applying them
as algorithms in a computer-friendly manner.
3. Improved efficiency: Artificial intelligence can automate tasks and processes that are
time-consuming and require a lot of human effort. This can help improve efficiency and
productivity, allowing humans to focus on more creative and high-level tasks.
4. Better decision-making: Artificial intelligence can analyze large amounts of data and
provide insights that can aid in decision-making. This can be especially useful in domains
like finance, healthcare, and logistics, where decisions can have significant impacts on
outcomes.
5. Enhanced accuracy: Artificial intelligence algorithms can process data quickly and
accurately, reducing the risk of errors that can occur in manual processes. This can
improve the reliability and quality of results.
6. Personalization: Artificial intelligence can be used to personalize experiences for users,
tailoring recommendations, and interactions based on individual preferences and
behaviors. This can improve customer satisfaction and loyalty.
7. Exploration of new frontiers: Artificial intelligence can be used to explore new frontiers
and discover new knowledge that is difficult or impossible for humans to access. This
can lead to new breakthroughs in fields like astronomy, genetics, and drug discovery.
History of AI:
To achieve the above factors for a machine or software Artificial Intelligence requires the
following discipline:
o Mathematics
o Biology
o Psychology
o Sociology
o Computer Science
o Neurons Study
o Statistics
Goals of AI:
1. Logical Reasoning
AI programs enable computers to perform sophisticated tasks. On February 10, 1996, IBM’s
Deep Blue computer won a game of chess against a former world champion, Garry
Kasparov.
2. Knowledge Representation
The process of enabling a computer to get from point A to point B. A prime example of this
is Google’s self-driving Toyota Prius.
5. Perception
Use computers to interact with the world through sight, hearing, touch, and smell.
6. Emergent Intelligence
Intelligence that is not explicitly programmed, but emerges from the rest of the specific AI
features. The vision for this goal is to have machines exhibit emotional intelligence and
moral reasoning.
Some of the tasks performed by AI-enabled devices include:
Speech recognition
Object detection
Advantages of AI:
It’s fast
Good at detail-oriented jobs. AI has proven to be just as good, if not better than
doctors at diagnosing certain cancers, including breast cancer and melanoma.
Saves labor and increases productivity. An example here is the use of warehouse
automation, which grew during the pandemic and is expected to increase with the
integration of AI and machine learning.
Delivers consistent results. The best AI translation tools deliver high levels of
consistency, offering even small businesses the ability to reach customers in their native
language.
Can improve customer satisfaction through personalization. AI can personalize
content, messaging, ads, recommendations and websites to individual customers.
AI-powered virtual agents are always available. AI programs do not need to sleep
or take breaks, providing 24/7 service.
Artificial Intelligence (AI) has become an integral part of our daily lives, revolutionizing
various industries and enhancing user experiences. Here are some notable examples of AI
applications:
ChatGPT
Google Maps
Google Maps utilizes AI algorithms to provide real-time navigation, traffic updates, and
personalized recommendations. It analyzes vast amounts of data, including historical traffic
patterns and user input, to suggest the fastest routes, estimate arrival times, and even predict
traffic congestion.
Smart Assistants
Smart assistants like Amazon's Alexa, Apple's Siri, and Google Assistant employ AI
technologies to interpret voice commands, answer questions, and perform tasks. These
assistants use natural language processing and machine learning algorithms to understand user
intent, retrieve relevant information, and carry out requested actions.
Snapchat Filters
Self-driving cars rely heavily on AI for perception, decision-making, and control. Using a
combination of sensors, cameras, and machine learning algorithms, these vehicles can detect
objects, interpret traffic signs, and navigate complex road conditions autonomously, enhancing
safety and efficiency on the roads.
Wearables
Wearable devices, such as fitness trackers and smartwatches, utilize AI to monitor and analyze
users' health data. They track activities, heart rate, sleep patterns, and more, providing
personalized insights and recommendations to improve overall well-being.
MuZero
These examples demonstrate the wide-ranging applications of AI, showcasing its potential to
enhance our lives, improve efficiency, and drive innovation across various industries.
1.2 APPLICATIONS OF AI
AI is used in NLP to analyze and understand human language. It powers applications such as
speech recognition, machine translation, sentiment analysis, and virtual assistants like Siri and
Alexa.
AI techniques, including computer vision, enable the analysis and interpretation of images and
videos. This finds application in facial recognition, object detection and tracking, content
moderation, medical imaging, and autonomous vehicles.
AI plays a crucial role in robotics and automation systems. Robots equipped with AI algorithms
can perform complex tasks in manufacturing, healthcare, logistics, and exploration. They can
adapt to changing environments, learn from experience, and collaborate with humans.
Recommendation Systems
AI-powered recommendation systems are used in e-commerce, streaming platforms, and social
media to personalize user experiences. They analyze user preferences, behavior, and historical
data to suggest relevant products, movies, music, or content.
Financial Services
AI is extensively used in the finance industry for fraud detection, algorithmic trading, credit
scoring, and risk assessment. Machine learning models can analyze vast amounts of financial
data to identify patterns and make predictions.
Healthcare
AI-powered virtual assistants and chatbots interact with users, understand their queries, and
provide relevant information or perform tasks. They are used in customer support, information
retrieval, and personalized assistance.
Gaming
AI algorithms are employed in gaming for creating realistic virtual characters, opponent
behavior, and intelligent decision-making. AI is also used to optimize game graphics, physics
simulations, and game testing.
AI enables the development of smart home systems that can automate tasks, control devices,
and learn from user preferences. AI can enhance the functionality and efficiency of Internet of
Things (IoT) devices and networks.
Cybersecurity
AI helps in detecting and preventing cyber threats by analyzing network traffic, identifying
anomalies, and predicting potential attacks. It can enhance the security of systems and data
through advanced threat detection and response mechanisms.
These are just a few examples of how AI is applied in various fields. The potential of AI is
vast, and its applications continue to expand as technology advances.
AI in healthcare
The biggest bets are on improving patient outcomes and reducing costs. Companies
are applying machine learning to make better and faster medical diagnoses than
humans. One of the best-known healthcare technologies is IBM Watson. It
understands natural language and can respond to questions asked of it. The system
mines patient data and other available data sources to form a hypothesis, which it
then presents with a confidence scoring schema. Other AI applications include using
online virtual health assistants and chatbots to help patients and healthcare
customers find medical information, schedule appointments, understand the billing
process and complete other administrative processes. An array of AI technologies is
also being used to predict, fight and understand pandemics such as COVID-19.
AI in business
Machine learning algorithms are being integrated into analytics and customer
relationship management (CRM) platforms to uncover information on how to better
serve customers. Chatbots have been incorporated into websites to provide
immediate service to customers. The rapid advancement of generative AI technology
such as ChatGPT is expected to have far-reaching consequences: eliminating jobs,
revolutionizing product design and disrupting business models.
AI in education
AI can automate grading, giving educators more time for other tasks. It can assess
students and adapt to their needs, helping them work at their own pace. AI tutors can
provide additional support to students, ensuring they stay on track. The technology
could also change where and how students learn, perhaps even replacing some
teachers. As demonstrated by ChatGPT, Google Bard and other large language
models, generative AI can help educators craft course work and other teaching
materials and engage students in new ways. The advent of these tools also forces
educators to rethink student homework and testing and revise policies on plagiarism.
AI in finance
AI in law
New generative AI tools can be used to produce application code based on natural
language prompts, but it is early days for these tools and unlikely they will replace
software engineers soon. AI is also being used to automate many IT processes,
including data entry, fraud detection, customer service, and predictive maintenance
and security.
Security
AI and machine learning are at the top of the buzzword list security vendors use to
market their products, so buyers should approach with caution. Still, AI techniques
are being successfully applied to multiple aspects of cybersecurity, including
anomaly detection, solving the false-positive problem and conducting behavioral
threat analytics. Organizations use machine learning in security information and
event management (SIEM) software and related areas to detect anomalies and
identify suspicious activities that indicate threats. By analyzing data and using logic
to identify similarities to known malicious code, AI can provide alerts to new and
emerging attacks much sooner than human employees and previous technology
iterations.
AI in manufacturing
Manufacturing has been at the forefront of incorporating robots into the workflow.
For example, the industrial robots that were at one time programmed to perform
single tasks and separated from human workers, increasingly function as cobots:
Smaller, multitasking robots that collaborate with humans and take on responsibility
for more parts of the job in warehouses, factory floors and other workspaces.
AI in banking
AI in transportation
The reflex agents are known as the simplest agents because they directly map states into actions.
Unfortunately, these agents fail to operate in an environment where the mapping is too large to
store and learn. Goal-based agent, on the other hand, considers future actions and the desired
outcomes.
One type of goal-based agent known as a problem-solving agent, which uses atomic
representation with no internal states visible to the problem-solving algorithms.
Problem-solving agent:
The problem-solving agent performs precisely by defining problems and its severalsolutions.
Problem Definition:
To build a system to solve a particular problem, we need to do four things:
(i) Define the problem precisely. This definition must include specification of the initial
situations and also final situations which constitute (i.e) acceptable solution to the problem.
(ii) Analyze the problem (i.e) important features have an immense (i.e) huge impact on the
appropriateness of various techniques for solving the problems.
(iii) Isolate and represent the knowledge to solve the problem.
(iv) Choose the best problem – solving techniques and apply it to the particular problem.
Steps performed by Problem-solving agent:
Search: It identifies all the best possible sequence of actions to reach the goal
state fromthe current state. It takes a problem as an input and returns solution as its
output.
Solution: It finds the best algorithm out of various algorithms, which may be
proven as thebest optimal solution.
Execution: It executes the best optimal solution from the searching algorithms to
reach thegoal state from the current state.
Example Problems
Toy Problem: It is a concise and exact description of the problem which is used by
the researchers to compare the performance of algorithms.
Real-world Problem: It is real-world based problems which require solutions.
Unlike a toyproblem, it does not depend on descriptions, but we can have a general
formulation of the problem.
8 Puzzle Problem:
Here, we have a 3×3 matrix with movable tiles numbered from 1 to 8 with a blank
space. The tile adjacent to the blank space can slide into that space. The objective is
to reach a specified goal state similar to the goal state, as shown in the below figure.
In the figure, our task is to convert the current state into goal state by sliding digits
into theblank space.
In the above figure, our task is to convert the current(Start) state into goal state by
sliding digits into the blank space.
The problem formulation is as follows:
States: It describes the location of each numbered tiles and the blank tile.
Initial State: We can start from any state as the initial state.
Actions: Here, actions of the blank space is defined, i.e., either left, right, up or
down
Transition Model: It returns the resulting state as per the given state and actions.
Goal test: It identifies whether we have reached the correct goal-state.
Path cost: The path cost is the number of steps in the path where the cost of each
step is 1. Note: The 8-puzzle problem is a type of sliding-block problem which is
used for testingnew search algorithms in artificial intelligence.
8-queens problem:
The aim of this problem is to place eight queens on a chessboard in an order where no
queen may attack another. A queen can attack other queens either diagonallyor in same
row and column.
From the following figure, we can understand the problem as well as its correct solution.
It is noticed from the above figure that each queen is set into the chessboard in a position
where no other queen is placed diagonally, in same row or column. Therefore, it is one right
approach tothe 8-queens problem.
For this problem, there are two main kinds of formulation:
1. Incremental formulation: It starts from an empty state where the operator augments a
queenat each step.
Following steps are involved in this formulation:
2. Complete-state formulation: It starts with all the 8-queens on the chessboard and
moves themaround, saving from the attacks.
States: Arrangement of all the 8 queens one per column with no queen attacking
the otherqueen.
Actions: Move the queen at the location where it is safe from the attacks.
This formulation is better than the incremental formulation as it reduces the state
space from 1.8 x1014 to 2057, and it is easy to find the solutions.
can visit each city only once. The objective is to find the shortest tour and sell-out the
stuff in each city.
VLSI Layout problem: In this problem, millions of components and connections are
positioned on a chip in order to minimize the area, circuit-delays, stray-capacitances,
and maximizing the manufacturing yield.
The layout problem is split into two parts:
Cell layout: Here, the primitive components of the circuit are grouped into cells, each
performing its specific function. Each cell has a fixed shape and size. The task is to place
the cells on the chip without overlapping each other.
Channel routing: It finds a specific route for each wire through the gaps between the
cells.
Protein Design: The objective is to find a sequence of amino acids which will fold into
We have seen many problems. Now, there is a need to search for solutions to solve them.
In this section, we will understand how searching can be used by the agent to solve a problem.
For solving different kinds of problem, an agent makes use of different strategies to reach
the goal by searching the best possible algorithms. This process of searching is known as
search strategy.
1.4 SEARCH ALGORITHMS
Search algorithms are one of the most important areas of Artificial Intelligence. This topic will
explain all about the search algorithms in AI.
Problem-solving agents:
Uninformed/Blind Search:
The uninformed search does not contain any domain knowledge 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 tree and how to identify leaf and goal nodes. Uninformed search applies a way in which
search tree is searched without any information about the search space like initial state
operators and test for the goal, so it is also called blind search. It examines each node of the
tree until it achieves the goal node.
It can be divided into five main types:
Breadth-first search
Uniform cost search
Depth-first search
Iterative deepening depth-first search
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.
Informed search can solve much complex problem which could not be solved in another way.
An example of informed search algorithms is a traveling salesman problem.
Greedy Search
A* Search
1.5 UNINFORMED SEARCH STRATEGIES
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:
Breadth-first Search
Depth-first Search
Depth-limited Search
Iterative deepening depth-first search
Uniform cost search
Bidirectional Search
1. Breadth-first Search:
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.
Advantages:
BFS will provide a solution if any solution exists.
If there are more than one solutions for a given problem, then BFS will provide the minimal
solution, which requires the least number of steps.
Disadvantages:
It requires lots of memory since each level of the tree must be saved into memory to expand
the next level.
BFS needs lots of time if the solution is far away from the root node.
Example:
In the below tree structure, we have shown the traversing of the tree 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:
S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Time Complexity: Time Complexity of BFS algorithm can be obtained by the number of
nodes traversed in BFS until the shallowest Node. Where the d= depth of shallowest solution
and b is a node at every state.
T (b) = 1+b2+b3+.......+ bd= O (bd)
Space Complexity: Space complexity of BFS algorithm is given by the Memory size of
frontier which is O(bd).
Completeness: BFS is complete, which means if the shallowest goal node is at some finite
depth, then BFS will find a solution.
Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of the node.
2. Depth-first Search
Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
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.
DFS uses a stack data structure for its implementation.
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.
Advantages:
DFS requires very less memory as it only needs to store a stack of the nodes on the
path from root node to the current node.
It takes less time to reach to the goal node than BFS algorithm (if it traverses in the
right path).
Disadvantages:
There is the possibility that many states keep re-occurring, and there is no guarantee
of finding the solution.
DFS algorithm goes for deep down searching and sometime it may go to the infinite
loop.
Example:
In the below search tree, we have shown the flow of depth-first search, and it will follow the
order as:
Root node--->Left node ----> right 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 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 node.
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:
T(n)= 1+ n2+ n3 +.........+ nm=O(nm)
Where, m= maximum depth of any node and this can be much larger than d (Shallowest
solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root node, hence
space complexity of DFS is equivalent to the size of the fringe set, which is O(bm).
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.
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:
Standard failure value: It indicates that problem does not have any solution.
Cut off failure value: It defines no solution for the problem within a given depth limit.
Advantage:
Depth-limited search is Memory efficient.
Disadvantages:
Depth-limited search also has a disadvantage of incompleteness.
It may not be optimal if the problem has more than one solution.
Example:
Completeness: DLS search algorithm is complete if the solution is above the depth-limit.
Time Complexity: Time complexity of DLS algorithm is O(bℓ).
Space Complexity: Space complexity of DLS algorithm is O(b×ℓ).
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 (UCS) is a type of uninformed search that performs a search based on
the lowest path cost. UCS helps us find the path from the starting node to the goal node with
the minimum path cost. Considering the scenario that we need to move from point A to point
B, which path would you choose? A->C->B or A->B:
The path cost of going from path A to path B is 5 and the path cost of path A to C to B is 4
(2+2). As UCS will consider the least path cost, that is, 4. Hence, A to C to B would be selected
in terms of uniform cost search.
Explanation
Concept:
Frontier list will be based on the priority queue. Every new node will be added at the
end of the list and the list will give priority to the least cost path.
The node at the top of the frontier list will be added to the expand list, which shows
that this node is going to be explored in the next step. It will not repeat any node. If the
node has already been explored, you can discard it.
Explored list will be having the nodes list, which will be completely explored.
Algorithm:
1. Add the Starting node S in the frontier list with the path cost g(n) = 0 (starting point is
at 0 path cost).
2. Add this node to the Explored list, as we only have a single node in the frontier list. If
we have multiple nodes, then we will add that one node at the top of the frontier.
3. Now, explore this node by visiting all of its child nodes. After that, add this node to
the Explored list, as it is now fully explored.
4. Check if the added node is the goal node or not. Stop if the goal node is found, or else
move on to the next step.
5. Since new nodes are added to the frontier list, we need to compare and set the priority
queue again, depending upon the priority, that is, the minimum path cost g(n).
6. Now, move to back to step 2 and repeat the steps until the goal node is not added to the
explored list.
Solutions:
Actual path: This is obtained by the frontier list.
Traversed path: This is obtained by the explored list.
Example
Consider the following graph. Let the starting node be A and the goal node be G.
mplementing UCS:
Hence we get:
Evaluation
The uniform cost search algorithm can be evaluated by four of the following factors:
A heuristic is a technique that is used to solve a problem faster than the classic
methods. These techniques are used to find the approximate solution of a problem
when classical methods do not. Heuristics are said to be the problem-solving
techniques that result in practical and quick solutions.
Heuristics are strategies that are derived from past experience with similar
problems. Heuristics use practical methods and shortcuts used to produce the
solutions that may or may not be optimal, but those solutions are sufficient in a
given limited timeframe.
History
Psychologists Daniel Kahneman and Amos Tversky have developed the study
of Heuristics in human decision-making in the 1970s and 1980s. However, this
concept was first introduced by the Nobel Laureate Herbert A. Simon, whose
primary object of research was problem-solving.
The heuristic method might not always provide us the finest solution, but it is
assured that it helps us find a good solution in a reasonable time.
Based on context, there can be different heuristic methods that correlate with the
problem's scope. The most common heuristic methods are - trial and error,
guesswork, the process of elimination, historical data analysis. These methods
involve simply available information that is not particular to the problem but is
most appropriate. They can include representative, affect, and availability
heuristics.
Heuristic search techniques in AI (Artificial Intelligence)
It includes Blind Search, Uninformed Search, and Blind control strategy. These
search techniques are not always possible as they require much memory and time.
These techniques search the complete space for a solution and use the arbitrary
ordering of operations.
The examples of Weak Heuristic search techniques include Best First Search
(BFS) and A*.
Before describing certain heuristic techniques, let's see some of the techniques
listed below:
o Bidirectional Search
o A* search
o Simulated Annealing
o Hill Climbing
o Best First search
o Beam search
Some of the real-life examples of heuristics that people use as a way to solve a
problem:
Types of heuristics
There are various types of heuristics, including the availability heuristic, affect
heuristic and representative heuristic. Each heuristic type plays a role in decision-
making. Let's discuss about the Availability heuristic, affect heuristic, and
Representative heuristic.
Availability heuristic
Availability heuristic is said to be the judgment that people make regarding the
likelihood of an event based on information that quickly comes into mind. On
making decisions, people typically rely on the past knowledge or experience of
an event. It allows a person to judge a situation based on the examples of similar
situations that come to mind.
Representative heuristic
So, instead of evaluating the product based on its quality, customers correlate the
products quality based on the similarity in packaging.
Affect heuristic
It is based on the negative and positive feelings that are linked with a certain
stimulus. It includes quick feelings that are based on past beliefs. Its theory is
one's emotional response to a stimulus that can affect the decisions taken by an
individual.
When people take a little time to evaluate a situation carefully, they might base
their decisions based on their emotional response.
If someone carefully analyzes the benefits and risks of consuming fast food, they
might decide that fast food is unhealthy. But people rarely take time to evaluate
everything they see and generally make decisions based on their automatic
emotional response. So, Fast food companies present advertisements that rely on
such type of Affect heuristic for generating a positive emotional response which
results in sales.
Limitation of heuristics
Conclusion
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.
At each point in the search space, only those node is expanded which have the lowest value
of f(n) and the algorithm terminates when the goal is found.
Algorithm of A* search:
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.
Advantages:
o It does not always produce the shortest path as it mostly based on heuristics and
approximation.
o A* search algorithm has some complexity issues.
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.
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.
Solution:
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
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.
o The efficiency of A* algorithm depends on the quality of heuristic.
o A* algorithm expands all nodes which satisfy the condition f(n)<="" li="">
Complete:
Optimal:
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.
Space Complexity:
Game playing is a popular application of artificial intelligence that involves the development
of computer programs to play games, such as chess, checkers, or Go. The goal of game
playing in artificial intelligence is to develop algorithms that can learn how to play games
and make decisions that will lead to winning outcomes.
1. One of the earliest examples of successful game playing AI is the chess program Deep
Blue, developed by IBM, which defeated the world champion Garry Kasparov in 1997.
Since then, AI has been applied to a wide range of games, including two-player games,
multiplayer games, and video games.
There are two main approaches to game playing in AI, rule-based systems and machine
learning-based systems.
Game playing in AI is an active area of research and has many practical applications,
including game development, education, and military training. By simulating game playing
scenarios, AI algorithms can be used to develop more effective decision-making systems for
real-world applications.
The most common search technique in game playing is Minimax search procedure. It is
depth-first depth-limited search procedure. It is used for games like chess and tic-tac-toe.
Minimax algorithm uses two functions –
MOVEGEN : It generates all the possible moves that can be generated from the current
position.
STATICEVALUATION : It returns a value depending upon the goodness from the
viewpoint of two-player
This algorithm is a two player game, so we call the first player as PLAYER1 and second
player as PLAYER2. The value of each node is backed-up from its children. For PLAYER1
the backed-up value is the maximum value of its children and for PLAYER2 the backed-up
value is the minimum value of its children. It provides most promising move to PLAYER1,
assuming that the PLAYER2 has make the best move. It is a recursive algorithm, as same
procedure occurs at each level.
1. Advancement of AI: Game playing has been a driving force behind the development of
artificial intelligence and has led to the creation of new algorithms and techniques that
can be applied to other areas of AI.
2. Education and training: Game playing can be used to teach AI techniques and
algorithms to students and professionals, as well as to provide training for military and
emergency response personnel.
3. Research: Game playing is an active area of research in AI and provides an opportunity
to study and develop new techniques for decision-making and problem-solving.
4. Real-world applications: The techniques and algorithms developed for game playing
can be applied to real-world applications, such as robotics, autonomous systems, and
decision support systems.
Disadvantages of Game Playing in Artificial Intelligence:
1. Limited scope: The techniques and algorithms developed for game playing may not be
well-suited for other types of applications and may need to be adapted or modified for
different domains.
2. Computational cost: Game playing can be computationally expensive, especially for
complex games such as chess or Go, and may require powerful computers to achieve real-
time performance.
1.9 ALPHA BETA PRUNING
1. α>=β
Let's take an example of two-player search tree to understand the working of Alpha-beta
pruning
Step 1: At the first step the, Max player will start first move from node A where α= -∞ and β=
+∞, these value of alpha and beta passed down to node B where again α= -∞ and β= +∞, and
Node B passes the same value to its child D.
Step 2: At Node D, the value of α will be calculated as its turn for Max. The value of α is
compared with firstly 2 and then 3, and the max (2, 3) = 3 will be the value of α at node D and
node value will also 3.
In the next step, algorithm traverse the next successor of Node B which is node E, and the
values of α= -∞, and β= 3 will also be passed.
Step 4: At node E, Max will take its turn, and the value of alpha will change. The current value
of alpha will be compared with 5, so max (-∞, 5) = 5, hence at node E α= 5 and β= 3, where
α>=β, so the right successor of E will be pruned, and algorithm will not traverse it, and the
value at node E will be 5.
Step 5: At next step, algorithm again backtrack the tree, from node B to node A. At node A,
the value of alpha will be changed the maximum available value is 3 as max (-∞, 3)= 3, and β=
+∞, these two values now passes to right successor of A which is Node C.
At node C, α=3 and β= +∞, and the same values will be passed on to node F.
Step 6: At node F, again the value of α will be compared with left child which is 0, and
max(3,0)= 3, and then compared with right child which is 1, and max(3,1)= 3 still α remains 3,
but the node value of F will become 1.
Step 7: Node F returns the node value 1 to node C, at C α= 3 and β= +∞, here the value of beta
will be changed, it will compare with 1 so min (∞, 1) = 1. Now at C, α=3 and β= 1, and again
it satisfies the condition α>=β, so the next child of C which is G will be pruned, and the
algorithm will not compute the entire sub-tree G.
Step 8: C now returns the value of 1 to A here the best value for A is max (3, 1) = 3. Following
is the final game tree which is the showing the nodes which are computed and nodes which has
never computed. Hence the optimal value for the maximizer is 3 for this example.
Move Ordering in Alpha-Beta pruning:
The effectiveness of alpha-beta pruning is highly dependent on the order in which each node
is examined. Move order is an important aspect of alpha-beta pruning.
o Worst ordering: In some cases, alpha-beta pruning algorithm does not prune any of
the leaves of the tree, and works exactly as minimax algorithm. In this case, it also
consumes more time because of alpha-beta factors, such a move of pruning is called
worst ordering. In this case, the best move occurs on the right side of the tree. The time
complexity for such an order is O(bm).
o Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of pruning
happens in the tree, and best moves occur at the left side of the tree. We apply DFS
hence it first search left of the tree and go deep twice as minimax algorithm in the same
amount of time. Complexity in ideal ordering is O(bm/2).
1. Variables as Placeholders:
Variables in CSPs act as placeholders for problem components that need to be assigned
values. They represent the entities or attributes of the problem under consideration. For
example:
• In a Sudoku puzzle, variables represent the empty cells that need numbers.
• In job scheduling, variables might represent tasks to be scheduled.
• In map coloring, variables correspond to regions or countries that need to be
colored.
The choice of variables depends on the specific problem being modeled.
2. Domains:
Each variable in a CSP is associated with a domain, which defines the set of values that
the variable can take. Domains are a critical part of the CSP representation, as they
restrict the possible assignments of values to variables. For instance:
• In Sudoku, the domain for each empty cell is the numbers from 1 to 9.
• In scheduling, the domain for a task might be the available time slots.
• In map coloring, the domain could be a list of available colors.
Domains ensure that variable assignments remain within the specified range of values.
3. Constraints:
Constraints in CSPs specify the relationships or conditions that must be satisfied by the
variables. Constraints restrict the combinations of values that variables can take.
Constraints can be unary (involving a single variable), binary (involving two variables),
or n-ary (involving more than two variables). Constraints are typically represented in
the form of logical expressions, equations, or functions. For example:
• In Sudoku, constraints ensure that no two numbers are repeated in the same row,
column, or subgrid.
• In scheduling, constraints might involve ensuring that two tasks are not scheduled at
the same time.
• In map coloring, constraints require that adjacent regions have different colors.
Constraint specification is a crucial part of problem modeling, as it defines the rules
that the variables must follow.
Overall Representation:
To represent a CSP, you need to define:
• The set of variables: What entities or attributes need values?
• The domains: What are the possible values that each variable can take?
• The constraints: What conditions or limitations must be satisfied by the variables?
By defining these elements, you create a structured representation of the problem,
which is essential for CSP solvers to find valid solutions efficiently.
Example:
In project scheduling, meeting deadlines can be considered a hard constraint,
but minimizing project costs can be a soft constraint where slight delays may be
acceptable if they reduce costs.
2. Global Constraints:
Global constraints are higher-level constraints that involve a larger number of
variables and often have a more complex relationship. They can express
relationships that would be cumbersome to specify using only binary
constraints. Global constraints help simplify the problem by encapsulating
multiple constraints into a single entity.
3. Optimization Problems:
In standard CSPs, the goal is to find any valid solution. However, in
optimization problems, the aim is to find the best solution among multiple
possibilities, based on an objective function. Optimization problems include
finding the minimum or maximum value of this function while satisfying
constraints.
Example: In job scheduling, finding the schedule that minimizes costs or
maximizes efficiency is an optimization problem.