0% found this document useful (0 votes)
6 views78 pages

AI & Machine Learning Course Overview

Uploaded by

727621bme027
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)
6 views78 pages

AI & Machine Learning Course Overview

Uploaded by

727621bme027
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

19MECC1701-ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 1


Course Title: Artificial Intelligence & Machine Learning
Course Code: 19MECC1701

Course Category: Professional Core Course Level: Mastery

L:T:P (Hours/Week) 3: 0: 0 Credits:3 Total Contact Hours:45 Max. Marks:100

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 2


Course Outcomes

Course Outcomes Cognitive


At the end of this course, students will be able to: Level

CO1: Explain the basic concept, and application of Artificial Intelligence.


Understand
CO2: Explain uninformed and informed search methods for problem solving. Understand

CO3: Explain knowledge representation using first order logic. Understand

CO4: Explain the basic concept, and application of Machine Learning. Understand

CO5: Explain the classification and clustering techniques for decision making. Understand

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 3


Text & Reference books
Text books:
Stuart J. Russell and Peter Norvig, “Artificial Intelligence- A Modern Approach”, Fourth Edition, Pearson
Series, 2021.
Tom M. Mitchell, “Machine Learning”, McGraw hill, 2013.
Reference books:
•George Lugar, “Al-Structures and Strategies for and Strategies for Complex Problem solving”, Sixth Edition,
2009, Pearson Educations.
•E. Rich and K. Knight, “Artificial intelligence”, McGraw Hill, 3rd ed., 2017.
•Robin R Murphy, “Introduction to AI Robotics”, PHI Publication, 2nd edition,2019.
•Nils.J. Nilsson, “Principles of AI”, Narosa Publ. House, 2000.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 4


Syllabus

UNIT- II PROBLEM SOLVING BY SEARCH (9hours)


Problem solving agents, searching for solutions- Infrastructure for search algorithms,
measuring problem-solving performance. Uninformed search strategies- Breadth-first
search, Depth-first search, Iterative deepening search, Uniform-cost search,
Bidirectional search, Comparing uninformed search strategies. Heuristic functions,
Informed (heuristic) search strategies- Best first search.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 5


Problem-solving agents:
• In Artificial Intelligence, Search techniques are universal problem-
solving methods.
• Rational agents or Problem-solving agents in AI mostly used these
search strategies or algorithms to solve a specific problem and provide
the best result.
• Problem-solving agents are the goal-based agents and use atomic
representation.
• In this topic, we will learn various problem-solving search algorithms.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 6


Search Algorithm Terminologies:
• Search: Searching is a step by step procedure to solve a search-problem
in a given search space. A search problem can have three main factors:
• Search Space: Search space represents a set of possible solutions, which
a system may have.
• Start State: It is a state from where agent begins the search.
• Goal test: It is a function which observe the current state and returns
whether the goal state is achieved or not.
• Search tree: A tree representation of search problem is called Search
tree. The root of the search tree is the root node which is
corresponding to the initial state.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 7


Search Algorithm Terminologies:

• Actions: It gives the description of all the available actions to


the agent.
• Transition model: A description of what each action do, can be
represented as a transition model.
• Path Cost: It is a function which assigns a numeric cost to each
path.
• Solution: It is an action sequence which leads from the start
node to the goal node.
• Optimal Solution: If a solution has the lowest cost among all
solutions.
Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 8
Properties of Search Algorithms:
• Criteria to measure the performance of search strategies
• Completeness: A search algorithm is said to be complete if it guarantees to
return a solution if at least any solution exists for any random input.
• Optimality: If a solution found for an algorithm is guaranteed to be the best
solution (lowest path cost) among all other solutions, then such a solution
for is said to be an optimal solution.
• Time Complexity: Time complexity is a measure of time for an algorithm to
complete its task.
• Space Complexity: It is the maximum storage space required at any point
during the search, as the complexity of the problem.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 9


Applications
• Some of the most popularly used problem solving with the help of
artificial intelligence are:

• 1. Chess.

• 2. Travelling Salesman Problem.

• 3. Tower of Hanoi Problem.

• 4. Water-Jug Problem.

• 5. N-Queen Problem

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 10


Problem Searching
• In general, searching refers to as finding information one needs.
• Searching is the most commonly used technique of problem solving in
artificial intelligence.
• The searching algorithm helps us to search for solution of particular
problem.
• Problem: Problems are the issues which comes across any system. A
solution is needed to solve that particular problem.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 11


Steps : Solve Problem Using Artificial Intelligence
• The process of solving a problem consists of five steps.
These are:

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 12


Problem Solving in Artificial Intelligence
• Defining The Problem: The definition of the problem must be included precisely. It should contain
the possible initial as well as final situations which should result in acceptable solution.

• 1. Analyzing The Problem: Analyzing the problem and its requirement must be done as few
features can have immense impact on the resulting solution.

• 2. Identification Of Solutions: This phase generates reasonable amount of solutions to the given
problem in a particular range.

• 3. Choosing a Solution: From all the identified solutions, the best solution is chosen basis on the
results produced by respective solutions.

• 4. Implementation: After choosing the best solution, its implementation is done.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 13


Measuring problem-solving performance

• Completeness: Is the algorithm guaranteed to find a solution


when there is one?
• Optimality: Does the strategy find the optimal solution?
• Time complexity: How long does it take to find a solution?
• Space complexity: How much memory is needed to perform the
search?

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 14


Types of search algorithms
• Based on the search problems we can classify the
search algorithms into uninformed (Blind search)
search and informed search (Heuristic search)
algorithms.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 15


Search Algorithm

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 16


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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 17


Uninformed/Blind Search:
• It can be divided into five main types:
• Breadth-first search
• Uniform cost search
• Depth-first search
• Iterative deepening depth-first search
• Bidirectional Search

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 18


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

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 19


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:
• Breadth-first Search
• Depth-first Search
• Depth-limited Search
• Iterative deepening depth-first search
• Uniform cost search
• Bidirectional Search
Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 20
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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 21


Breadth-first Search
Level-0
A

Level-1
B C

D E F G Level-2
Note: Explain it clearly
during exams based on the
class lecture.
Simply sketch the given
H I J Level-3
diagram will not give marks.
Refer Example Depth-First
Search regarding the way to
write in exam.
K Level-4

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 22


1. Breadth-first Search:
• s = the depth of the shallowest solution.
• ni = number of nodes in level i .
• Time complexity: Equivalent to the number of nodes traversed in BFS until the shallowest solution.
T(n) = 1 + n2 + n3 + ... + ns = O(ns )
• Space complexity: Equivalent to how large can the fringe get. S(n) = O(ns)
• Completeness: BFS is complete, meaning for a given search tree, BFS will come up with a solution if it
exists.
• Optimality: BFS is optimal as long as the costs of all edges are equal.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 23


1. Breadth-first Search:
Time Complexity
The time complexity of an algorithm describes how the algorithm’s runtime grows as the
input size increases.
It is denoted using big O notation, such as O(f(n)), where “f(n)” represents the function that
defines the upper bound on the growth rate of the algorithm.
For example, O(n) means the algorithm’s runtime grows linearly with the input size, O(n²)
means the runtime grows quadratically, and O(log n) means the runtime grows
logarithmically.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 24


1. Breadth-first Search:
Space Complexity

The space complexity of an algorithm describes how much additional space or memory the
algorithm requires to solve a problem as the input size increases.

It is also denoted using big O notation, such as O(f(n)), where “f(n)” represents the function
that defines the upper bound on the space used by the algorithm.

The space complexity considers both the auxiliary space (additional space used by the
algorithm itself) and the input space (space required to store the input).

Similar to time complexity, space complexity can have different notations like O(1) for
constant space, O(n) for linear space, O(n²) for quadratic space, etc.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 25


1. Breadth-first Search:
In BFS, the time complexity is also determined by the number of vertices (nodes) and
edges in the graph.
BFS visits all the vertices at each level of the graph before moving to the next level.
Therefore, the time complexity of BFS is O(V + E), where V represents the number of
vertices and E represents the number of edges in the graph.

The space complexity of BFS depends on the maximum number of vertices in the queue
at any given time.
In the worst case, if the graph is a complete graph, all vertices at each level will be stored
in the queue.
Therefore, the space complexity of BFS is O(V), where V represents the number of
vertices in the graph.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 26


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.
• Advantage:
• 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).
• Disadvantage:
• 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 27


Depth-First Search – Example
• Let us consider the following tree. Here node ‘A’ is the source or start or initial node and node ‘G’ is the goal
node.
• Step 1: Initially NODE-LIST contains only one node corresponding to the source state A.
• NODE-LIST: A

Step 2: Node A is removed from NODE-LIST. A is expanded and its children B and C are put in front of NODE-LIST.

NODE-LIST: B C

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 28


Depth-First Search – Example
•Step 3: Node B is removed from NODE-LIST, and its children D and E are pushed in front of NODE-LIST.
NODE-LIST: D E C

Step 4: Node D is removed from NODE-LIST. C and F are pushed in front of NODE-LIST.
NODE-LIST: C F E C

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 29


Depth-First Search – Example
•Step 5: Node C is removed from NODE-LIST. Its child G is pushed in front of NODE-LIST .
NODE-LIST: G F E C

Step 6: Node G is expanded and found to be a goal node.


NODE-LIST: G F E C

The solution path A-B-D-C-G is returned and the algorithm terminates.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 30


Depth-First Search – Example
In DFS, the time complexity is determined by the number of vertices (nodes) and edges in the graph.
For each vertex, DFS visits all its adjacent vertices recursively.
In the worst case, DFS may visit all vertices and edges in the graph.
Therefore, the time complexity of DFS is O(V + E), where V represents the number of vertices and E represents the
number of edges in the graph.
The space complexity of DFS depends on the maximum depth of recursion.
In the worst case, if the graph is a straight line or a long path, the DFS recursion can go as deep as the
number of vertices.
Therefore, the space complexity of DFS is O(V), where V represents the number of vertices in the graph.

• Completeness: DFS is complete if the search tree is finite, meaning for a given finite search
tree, DFS will come up with a solution if it exists.
• Optimality: DFS is not optimal, meaning the number of steps in reaching the solution, or the
cost spent in reaching it is high.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 31


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.
• Cutoff failure value: It defines no solution for the problem within a given depth limit.
• Advantages:
• 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 32


Depth-Limited Search Algorithm
S Level-0

Level-1
A B

C D I J Level-2

G H Level-3
E F
Note: Explain it clearly
during exams based on the
class lecture.
Simply sketch the given
diagram will not give marks.
Limit-2Level Refer Example Depth-First
Search regarding the way to
Target-J write in exam.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 33


3. Depth-Limited Search Algorithm:
• 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 34


4. Uniform-cost Search Algorithm:
Uniform-cost search is a searching algorithm used for traversing a weighted tree or graph.
This algorithm comes into play when a different cost is available for each edge. The primary
goal of the uniform-cost search is to find a path to the goal node which has the lowest
cumulative cost. Uniform-cost search expands nodes according to their path costs form the
root node. It can be used to solve any graph/tree where the optimal cost is in demand. A
uniform-cost search algorithm is implemented by the priority queue. It gives maximum
priority to the lowest cumulative cost. Uniform cost search is equivalent to BFS algorithm if
the path cost of all edges is the same.
• Advantages:
• Uniform cost search is optimal because at every state the path with the least cost is
chosen.
• Disadvantages:
• It does not care about the number of steps involve in searching and only concerned
about path cost. Due to which this algorithm may be stuck in an infinite loop.
Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 35
Uniform-cost Search Algorithm
Level-0

G-Goalnode 1
S 4
Level-1
A B
3
2 5
Level-2
C D G
3
5 4
Level-3
G
E F
5

G Level-4

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 36


The uniform cost search algorithm can be evaluated by four of the following factors:
Completeness: UCS is complete if the branching factor b is finite.

Time complexity: The time complexity of UCS is exponential O(b(1+C/ε) ),because every node is
checked.
Space completeness: The space complexity is also exponential O(b(1+C/ε) ) because all the
nodes are added to the list for comparisons of priority.
b: The branching factor, representing the maximum number of successors for any node.
C: The cost of the optimal solution.
ε: The minimum cost between any two states.
The Uniform Cost Search algorithm explores nodes in a way that prioritizes nodes with the lowest accumulated cost so
far. The algorithm's time complexity is exponential in the ratio of C to ε. If ε is relatively large as compared to C then the
time complexity is reasonable. However, if the value of ε is smaller compared to C then the time complexity of the
algorithm increases and may become impractical.

Optimality: UCS gives the optimal solution or path to the goal node.
5. Iterative deepening depth-first Search:
• The iterative deepening algorithm is a combination of DFS and BFS algorithms. This search
algorithm finds out the best depth limit and does it by gradually increasing the limit until a goal
is found.
• This algorithm performs depth-first search up to a certain "depth limit", and it keeps increasing
the depth limit after each iteration until the goal node is found.
• This Search algorithm combines the benefits of Breadth-first search's fast search and depth-first
search's memory efficiency.
• The iterative search algorithm is useful uninformed search when search space is large, and depth
of goal node is unknown.
• Advantages:
• It combines the benefits of BFS and DFS search algorithm in terms of fast search and memory efficiency.
• Disadvantages:
• The main drawback of IDDFS is that it repeats all the work of the previous phase.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 38


Iterative deepening depth-first Search

Level-0
A
A
B Level-1 ABCD
D
C
H
Level-2 ABECFGDH
E F G

I J K

H-Goalnode

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 39


5. Iterative deepening depth-first Search:
•In IDDFS, the algorithm explores nodes up to a depth limit of ddd in each iteration, where ddd increases by 1 in each
step.
•Although IDDFS performs a depth-first search multiple times, most of the nodes are visited in the deepest level, i.e.,
at depth d.
•The nodes are revisited several times in shallower levels, but since the number of nodes at shallow depths is
significantly smaller than the number of nodes at the deepest level, the overhead is not significant.
The time complexity is therefore given by:
Time Complexity== O(bd)
This is because, despite the repeated exploration of nodes at shallower depths, the total number of nodes explored in
the last iteration dominates the time complexity, which is the same as DFS.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 40


5. Iterative deepening depth-first Search:

Space Complexity of IDDFS


The space complexity of IDDFS is very efficient and can be understood as follows:
•IDDFS, like DFS, only needs to store the current path from the root to the leaf node and
some additional information (e.g., the depth level).
•The space required for this path is proportional to the depth of the deepest node, which
is d.
•The space required is therefore linear in the depth of the tree.
Thus, the space complexity of IDDFS is:
Space Complexity=O(d)

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 41


6. Bidirectional Search Algorithm:
• Bidirectional search algorithm runs two simultaneous searches, one form initial state called
as forward-search and other from goal node called as backward-search, to find the goal
node.
• Bidirectional search replaces one single search graph with two small subgraphs in which
one starts the search from an initial vertex and other starts from goal vertex. The search
stops when these two graphs intersect each other.
• Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
• Advantages:
• Bidirectional search is fast.
• Bidirectional search requires less memory
• Disadvantages:
• Implementation of the bidirectional search tree is difficult.
• In bidirectional search, one should know the goal state in advance.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 42


Bidirectional Search Algorithm
Intersection node

Initial node 1 12

5 Forward Backward 10
search search
2 13
9
7 8
3
14
6 11

4 Goal
15
node
Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 43
Bidirectional Search Algorithm-Example-2

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 44


Bidirectional Search Algorithm

Performance measures

Completeness : Bidirectional search is complete if BFS is used in


both searches.
Optimality : It is optimal if BFS is used for search and paths have
uniform cost.

Time and Space Complexity : Time and space complexity is O(bd/2).

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 45


Bidirectional Search Algorithm

Time Complexity Analysis:


•In a typical unidirectional search, the time complexity is O(bd), where the algorithm
explores all possible nodes up to the depth d.
•In Bidirectional Search, the search is conducted simultaneously from the start node and the
goal node. Each search only needs to explore nodes up to half the depth, d/2
•Thus, the time complexity for each search is O(b d/2 ) Since there are two searches
happening simultaneously, the total time complexity becomes:

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 46


Bidirectional Search Algorithm

Space Complexity of Bidirectional Search


The space complexity of Bidirectional Search is typically the most significant drawback:
[Link] for Storing Nodes: Both searches (from the start and the goal) require storing all
nodes at the frontier (the boundary of the explored area) in memory.
[Link] for Each Frontier: At each level, the number of nodes in the frontier can be as large
as O(bd/2)in each direction.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 47


19MECC1701- Artificial Intelligence & Machine Learning 48
Dept of Mechanical Engineering
Informed Search Algorithms
• So far we have talked about the uninformed search algorithms which looked
through search space for all possible solutions of the problem without having
any additional knowledge about search space.
• But 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.

19MECC1701- Artificial Intelligence & Machine Learning 49


Dept of Mechanical Engineering
Heuristics function
• 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.

19MECC1701- Artificial Intelligence & Machine Learning 50


Dept of Mechanical Engineering
Heuristics function
• Admissibility of the heuristic function is given as:
• h(n) <= h*(n)
• Here h(n) is heuristic cost, and h*(n) is the estimated cost.
Hence heuristic cost should be less than or equal to the
estimated cost.

19MECC1701- Artificial Intelligence & Machine Learning 51


Dept of Mechanical Engineering
Pure Heuristic Search:
• Pure heuristic search is the simplest form of heuristic search algorithms. It
expands nodes based on their heuristic value h(n).
• It maintains two lists, OPEN and CLOSED list. In the CLOSED list, it places those
nodes which have already expanded and in the OPEN list, it places nodes
which have yet not been expanded.
• The heuristic function is a function used to measure the closeness of the
current state to the goal state and heuristic properties are used to find out the
best possible path to reach the goal state concerning the path cost.
• Consider an example of searching a place you want to visit on Google maps.
The current location and the destination place are given to the search
algorithm for calculating the accurate distance, time taken, and real-time
traffic updates on that particular route. This is executed using informed search
algorithms.
19MECC1701- Artificial Intelligence & Machine Learning 52
Dept of Mechanical Engineering
Pure Heuristic Search
• It is a simple search performed based on a heuristic value denoted by h(n). It maintains two
lists OPEN for new and unexpanded nodes and CLOSE for expanded nodes.

• The node with the smallest heuristic value is expanded for every iteration. And then all its
child nodes are expanded and added to the closed list.

• A heuristic function is then applied to the closed list and the node with the shortest path is
saved and the others are dispersed.

• The heuristic method, however, might not always give the best solution, but it guaranteed
to find a good solution in reasonable time.

19MECC1701- Artificial Intelligence & Machine Learning 53


Dept of Mechanical Engineering
Pure Heuristic Search
• The algorithm starts with the initial state node on the open list.
• Node with the minimum h(n) value on the open list is expanded at each cycle and generates
its child nodes and is kept in the closed list. The heuristic function is then applied to the child
nodes and is placed on the open list based on their heuristic values.
• The procedure continues until the goal state is selected for expansion.
• In pure heuristic search for a given heuristic function, The simplest method used is

• f(n) = h(n)
where f(n) is the cost function and h(n) is the heuristic function. For a PHS algorithm, it doesn’t
guarantee to terminate with an infinite graph even if there exists a goal node.

19MECC1701- Artificial Intelligence & Machine Learning 54


Dept of Mechanical Engineering
Example

Here a solution of length 4 is returned even there


exists one with length 3. PHS only considers h(n),
the heuristic function or the estimated cost to the
goal while expanding a node, or the cost to reach
the goal node from the node n.

It doesn’t consider the cost to reach node n from


start state g(n)

19MECC1701- Artificial Intelligence & Machine Learning 55


Dept of Mechanical Engineering
Advantages & Disadvantages

Advantages Disadvantages

•Provides a quick feedback •For applying heuristic effectively,

•Early feedback in the design process knowledge and experience are required.
•The evaluation concern more minor issues
and fewer major issues.

19MECC1701- Artificial Intelligence & Machine Learning 56


Dept of Mechanical Engineering
1.) 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, i.e.
• 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.

19MECC1701- Artificial Intelligence & Machine Learning 57


Dept of Mechanical Engineering
Best first 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.

19MECC1701- Artificial Intelligence & Machine Learning 58


Dept of Mechanical Engineering
Advantages & Disadvantages
• Advantages:
• Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.
• This algorithm is more efficient than BFS and DFS algorithms.
• Disadvantages:
• It can behave as an unguided depth-first search in the worst case
scenario.
• It can get stuck in a loop as DFS.
• This algorithm is not optimal.

19MECC1701- Artificial Intelligence & Machine Learning 59


Dept of Mechanical Engineering
Example:
• Consider the below search problem, and we will traverse it using greedy best-
first search. At each iteration, each node is expanded using evaluation
function f(n)=h(n) , which is given in the below table.

19MECC1701- Artificial Intelligence & Machine Learning 60


Dept of Mechanical Engineering
Example
• In this search example, we are using two lists which are OPEN and CLOSED Lists.
• Expand the nodes of S and put in the CLOSED list
• Initialization: Open [A, B], Closed [S]
• Iteration 1: Open [A], Closed [S, B]
• Iteration 2: Open [E, F, A], Closed [S, B]
• : Open [E, A], Closed [S, B, F]
• Iteration 3: Open [I, G, E, A], Closed [S, B, F]
• : Open [I, E, A], Closed [S, B, F, G]

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

19MECC1701- Artificial Intelligence & Machine Learning 61


Dept of Mechanical Engineering
Best first search algorithm:
Time Complexity of Best-First Search

The time complexity of Best-First Search depends on the following factors:

[Link] Factor (b): The average number of child nodes per node.

[Link] of the Solution (d): The depth at which the goal node is located.

[Link] of the Heuristic: The accuracy of the heuristic function in guiding the search

towards the goal.

19MECC1701- Artificial Intelligence & Machine Learning 62


Dept of Mechanical Engineering
Best first search algorithm:
Time Complexity Analysis:
•In the worst case, Best-First Search may need to explore a large number of nodes before
finding the goal. If the heuristic is not informative, it might perform similarly to an
uninformed search.
•In general, the time complexity is O(bd) similar to that of Depth-First Search (DFS) or
Breadth-First Search (BFS), but the actual performance can vary depending on the
heuristic.
Time Complexity=O(bd)

19MECC1701- Artificial Intelligence & Machine Learning 63


Dept of Mechanical Engineering
Space Complexity of Best-First Search
The space complexity of Best-First Search is primarily determined by the following factors:
[Link] Queue: Best-First Search uses a priority queue (often implemented as a min-
heap) to store the frontier nodes, sorted according to their heuristic values.
[Link] of Nodes: At any point, the priority queue might contain up to O(bd) nodes,
especially when exploring deep or wide search spaces.
Space Complexity Analysis:
•The space complexity is primarily governed by the number of nodes stored in the priority
queue.
•In the worst case, the space complexity is O(bd)as the priority queue could store all the
nodes at the deepest level before the goal is found.
Space Complexity=O(bd)
Try it by yourself using Greedy Search Algorithm

In this problem C is the initial/Source node


and Z is the goal node

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


65
A* Search Algorithm:
• A* search is the most commonly known form of best-first search. It uses heuristic function h(n), and
cost to reach the node n from the 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.
• 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.
• Simply put, A* search combines elements and strengths from a greedy search and a Uniform cost
search. 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


66
Algorithm of A* search:
• 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


67
Advantages & Disadvantages
• Advantages:
• A* search algorithm is the best algorithm than other search algorithms.
• A* search algorithm is optimal and complete.
• This algorithm can solve very complex problems.
• Disadvantages:
• It does not always produce the shortest path as it mostly based on heuristics and
approximation.
• A* search algorithm has some complexity issues.
• 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.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


68
Example
F(s)=0+14=14
S----B=4+12=16
S----C=3+11=14
SC---d=3+7+6=16
SC---e=3+10+4=17
SB---f=4+5+11=20
SB---e=4+12+4=20

SCd----e=3+7+2+4=16
SCde----g=3+7+2+5+0=17

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


69
Key Components of A* Search
•g(n): The cost of the path from the start node to node n.
•h(n): The heuristic estimate of the cost from node n to the goal.
•f(n)=g(n)+h(n): The estimated total cost of the cheapest solution through node n.
A* selects the node with the lowest f(n) value to expand next.
Time Complexity of A* Search
The time complexity of A* Search depends on several factors:
[Link] Factor (b): The average number of child nodes per node.
[Link] of the Optimal Solution (d): The depth at which the goal node is located.
[Link] Function h(n): The quality of the heuristic used.
Time Complexity Analysis:
•In the worst case, A* might explore all nodes up to the optimal solution's depth d. The number of nodes expanded
depends heavily on the heuristic h(n).
•If the heuristic h(n) is admissible (never overestimates the true cost) and consistent (or monotonic), A* is guaranteed
to find the optimal solution. However, the time complexity in the worst case can be exponential, similar to DFS or BFS.

Time Complexity=O(bd)
Space Complexity of A* Search
The space complexity of A* is typically its major drawback:
[Link] Queue: A* uses a priority queue to store all the generated nodes. The queue is sorted based
on the f(n) values.
[Link] Usage: In the worst case, A* needs to store all the nodes it generates, which could be as
many as O(bd) nodes
Space Complexity Analysis:
•The space complexity is determined by the maximum number of nodes that can be
stored in the priority queue at any time, which can be as large as O(bd) in the worst case.
Space Complexity=O(bd)
Points to remember:A* algorithm
• A* algorithm returns the path which occurred first, and it does not search for
all remaining paths.
• The efficiency of A* algorithm depends on the quality of heuristic.
• A* algorithm expands all nodes which satisfy the condition f(n)
• Complete: A* algorithm is complete as long as:
• Branching factor is finite.
• Cost at every action is fixed.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


73
Points to remember:A* algorithm
• Optimal: A* search algorithm is optimal if it follows below two conditions:

• 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.

• 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: The space complexity of A* search algorithm is O(b^d)

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


74
Difference between Informed and Uninformed Search in AI

• Informed Search algorithms have information on the goal state which helps in
more efficient searching. This information is obtained by a function that
estimates how close a state is to the goal state.

• Example: Greedy Search and Graph Search.

• Uninformed Search algorithms have no additional information on the goal node


other than the one provided in the problem definition. The plans to reach the
goal state from the start state differ only by the order and length of actions.

• Examples: Depth First Search and Breadth-First Search.


Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning
75
Difference between Informed and Uninformed Search in AI

Parameters Informed Search Uninformed Search


It is also known as Heuristic
Known as It is also known as Blind Search.
Search.
It uses knowledge for the searching It doesn’t use knowledge for the searching
Using Knowledge
process. process.
It finds solution slow as compared to an
Performance It finds a solution more quickly.
informed search.
Completion It may or may not be complete. It is always complete.
Cost Factor Cost is low. Cost is high.
It consumes less time because of It consumes moderate time because of slow
Time
quick searching. searching.

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


76
Difference between Informed and Uninformed Search in AI
Parameters Informed Search Uninformed Search
There is a direction given about the
Direction No suggestion is given regarding the solution in it.
solution.
Implementation It is less lengthy while implemented. It is more lengthy while implemented.
It is more efficient as efficiency takes into
It is comparatively less efficient as incurred cost is
account cost and performance. The
Efficiency more and the speed of finding the Breadth-
incurred cost is less and speed of finding
Firstsolution is slow.
solutions is quick.
Computational
Computational requirements are lessened. Comparatively higher computational requirements.
requirements
Having a wide scope in terms of handling
Size of search problems Solving a massive search task is challenging.
large search problems.
• Greedy Search
• Depth First Search (DFS)
• A* Search
Examples of Algorithms • Breadth First Search (BFS)
• AO* Search
• Branch and Bound
• Hill Climbing Algorithm

Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning


77
Dept of Mechanical Engineering 19MECC1701- Artificial Intelligence & Machine Learning 74

You might also like