Unit 2
Unit 2
Unit 2
ARTIFICIAL INTELLIGENGE
(R18 Regulations)
By
Dr.Vijender Kr. Solanki
Dr.A.Nirmal Kumar
1
ARTIFICIAL INTELLIGENCE
UNIT – II
Search Algorithms
Random search
Search with closed and open list
Depth first and Breadth first search
Heuristic search
Best first search
A* algorithm
Game Search
Search Algorithms in AI
Artificial Intelligence is the study of building agents that act
rationally. Most of the time, these agents perform some kind
of search algorithm in the background in order to achieve
their tasks.
• A search problem consists of:
– A State Space. Set of all possible states where you can be.
– A Start State. The state from where the search begins.
– A Goal Test. A function that looks at the current state returns
whether or not it is the goal state.
• The Solution to a search problem is a sequence of actions,
called the plan that transforms the start state to the goal
state.
• This plan is achieved through search algorithms.
Search Terminology
• Problem Space − It is the environment in which the search takes place. (A set
of states and set of operators to change those states)
• Problem Instance − It is Initial state + Goal state.
• Problem Space Graph − It represents problem state. States are shown by nodes
and operators are shown by edges.
• Depth of a problem − Length of a shortest path or shortest sequence of
operators from Initial State to goal state.
• Space Complexity − The maximum number of nodes that are stored in
memory.
• Time Complexity − The maximum number of nodes that are created.
• Admissibility − A property of an algorithm to always find an optimal solution.
• Branching Factor − The average number of child nodes in the problem space
graph.
• Depth − Length of the shortest path from initial state to goal state.
Single-player games
• Sudoku
• Crossword
Single-agent-path-finding Problems
• 3X3 eight-tile
• 4X4 fifteen-tile
• 5X5 twenty four tile puzzles
• Travelling Salesman Problem
• Rubik’s Cube
• Theorem Proving
Random Search
• Random search (RS) is a family of numerical optimization
methods that do not require the gradient of the problem to be
optimized, and RS can hence be used on functions that are
not continuous or differentiable. Such optimization methods
are also known as direct-search, derivative-free, or black-box
methods.
• The name "random search" is attributed to Rastrigin who
made an early presentation of RS along with basic
mathematical analysis. RS works by iteratively moving to
better positions in the search-space, which are sampled from
a hypersphere surrounding the current position.
Random Search Algorithm
• Let f: ℝn → ℝ be the fitness or cost function which must
be minimized. Let x ∈ ℝn designate a position or
candidate solution in the search-space. The basic RS
algorithm can then be described as:
• Initialize x with a random position in the search-space.
• Until a termination criterion is met (e.g. number of
iterations performed, or adequate fitness reached), repeat
the following:
– Sample a new position y from the hypersphere of a given
radius surrounding the current position x (see e.g. Marsaglia's
technique for sampling a hypersphere.)
– If f(y) < f(x) then move to the new position by setting x = y
Search with closed and open list
Pure Heuristic Search
• It expands nodes in the order of their heuristic values.
It creates two lists, a closed list for the already
expanded nodes and an open list for the created but
unexpanded nodes.
• In each iteration, a node with a minimum heuristic
value is expanded, all its child nodes are created and
placed in the closed list. Then, the heuristic function is
applied to the child nodes and they are placed in the
open list according to their heuristic value. The shorter
paths are saved and the longer ones are disposed.
TYPES OF SEARCH ALGORITHMS
I. Brute-Force Search Strategies (Uninformed / Blind)
• Breadth-First Search
• Depth-First Search
• Bidirectional Search
• Uniform Cost Search
• Iterative Deepening Depth-First Search
II. Informed (Heuristic) Search Strategies
• Pure Heuristic Search (Open and Closed List)
• Greedy Best First Search
• A * Search
III. Local Search Algorithms
• Hill-Climbing Search
• Local Beam Search
• Simulated Annealing
• Travelling Salesman Problem
UNINFORMED SEARCH ALGORITHMS
• The search algorithms in this section 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/or
length of actions. Uninformed search is also called Blind search.
• The following uninformed search algorithms are discussed in this section.
1. Depth First Search
2. Breath First Search
3. Uniform Cost Search
• Each of these algorithms will have:
A problem graph, containing the start node S and the goal node G.
A strategy, describing the manner in which the graph will be traversed
to get to G .
A fringe, which is a data structure used to store all the possible states
(nodes) that you can go from the current states.
A tree, that results while traversing to the goal node.
A solution plan, which the sequence of nodes from S to G.
UNINFORMED SEARCH STRATEGIES
1. Breadth-first search
2. Uniform-cost search
3. Depth-first search
4. Depth-limited search
5. Iterative deepening search
6. Bidirectional Search
BREADTH FIRST SEARCH
h(n) = estimated cost of the cheapest path from node n to a goal node.
• For example,in Romania, one might estimate the cost of the cheapest path
from Arad to Bucharest via a straight-line distance from Arad to
Bucharest
• Heuristic function are the most common form in which additional
knowledge is imparted to the search algorithm.
Greedy Best-first search
Points to remember:
• 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.
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)