Search Techniques
By - Er. Suraj Awal
- Uninformed Search (BFS, DFS,
DLS)
- Informed Search (Hill Climbing,
Simulated Annealing, Best First
Search, Greedy Search, A*,
Minimax, Alpha Beta Pruning)
- Evaluation of Search Strategy
Inside the Box
Searching
- Searching is the process of finding the goal state from its current state in a
state space using a successor function; ultimately generating a solution for
a problem.
- Initially, V = {S}, where S is the initial state. When S is expanded, its
successor are generated and those nodes are added to V and the
associated arcs are added to E. This process continues until a goal node is
found.
Uninformed Search
- Blind search
- Information about the problem definition only
- No additional information about the state space
- Typically visits all the nodes of a tree in certain order looking for a goal
- Able to expand current state to get a new set of states
- Able to distinguish goal state from non-goal state.
- Less effective
- Example : Breadth First Search (BFS), Depth First Search (DFS) and Depth
Limit Search (DLS)
Breadth First Search
- Proceeds level by level down the search tree
- Starting from the root node, it explores all the children from left to right
- If no solution is found, expands leftmost child of root node, then expands
second node at same depth and so on.
Breadth First Search (Algorithm)
1. Place the start node at the end of the queue
2. Examine the node at the start of the queue
a) If the queue is empty, stop
b) If the node is goal node, stop
c) Else, add the children of the node at the end of the queue
3. Repeat step 2
Depth First Search
- Proceeds down a single branch at a time
- Expands root node, then leftmost child and so on until the deepest level
Depth First Search (Algorithm)
1. Place the start node at the end of the stack
2. Examine the node at the end of the stack
a) If the stack is empty, stop (No solution)
b) If the node is goal node, stop (Solution found)
c) Else, add the children of the node at the end of the stack
3. Repeat step 2
Depth Limit Search
- Same as Depth first search
- But the depth limit is specified to level ‘l’
Properties of Uninformed Search Algorithms
Time
Complexity?
Space
Complexity?
Complete? Minimal?
BFS O(bd+1) O(bd) Yes Yes
DFS O(bd+1) O(b*d) No No
DLS O(bl+1) O(b*l) No No
Informed Search
- Heuristic search
- Heuristic is a technique designed to solve a problem quickly
- Information about the problem definition along with specific problem
knowledge
- Evaluate which of the nodes on frontier are more promising
- Develop domain specific heuristic function h(n) that guesses the cost of
getting to the goal from node n
- Eg : Best first search, Hill climbing, Simulated annealing, A*, and so on.
Hill Climbing Algorithm
- Used for mathematical optimization problems in the field of AI
- Variant of Depth first search that selects the next node based on estimate of
heuristic
- Practical Examples : n Queens, Toy problem
Hill Climbing Algorithm
1. Evaluate the initial state. If it is the goal state, then stop. Else, make initial
state as current state
2. Expand the current state
3. Choose the state that have good fitness than current state and make that
state as current state
4. Repeat from step 2 until solution is found or there are no new states that
can be applied to current state.
Hill Climbing Algorithm (Problems)
1. Local maxima (Backtracking)
2. Plateau (Big jump)
3. Ridge (Bi-directional search)
Simulated Annealing
- Just like hill climbing algorithm
- Allows downhill step to escape local maxima
- Uses a control parameter T, that is high at starting and gradually decreases
towards 0
- A bad move from A to B [ f(A) > f(B) ] is accepted with probability:
P = e ( f(B) - f(A) ) / T
- Higher T, likelihood of making bad move is high
- As T tends to 0, P tends to 0. It means, it acts as hill climbing algorithm
Greedy Search
- Tries to get as close as it can to the goal
- Expands the node that is closest to the goal
- Evaluation function : f(n) = h(n)
- It does not guarantee solution (May trap in the loop)
- It is not optimal
Greedy Search (Algorithm)
1. Initialize current node as initial node
2. Is h(current_node) = 0?
3. If yes, return success
4. If no,
a) Expand the node
b) Assign the node with least f(n) or h(n) as current node
1. Repeat from step 2
A* Search
- Combines path cost and heuristic to form evaluation function
- f(n) = g(n) + h(n)
- It is complete if h(n) is admissible or valid
- It is optimal if h(n) is consistent or same
A* Search
1. Initialize current node as initial node
2. Is h(current_node) = 0?
3. If yes, return success
4. If no,
a) Expand the node
b) Assign the node with least f(n) as current node : f(n) = g(n) + h(n)
1. Repeat from step 2
Minimax Algorithm
- Algorithm to find optimal move in a two player game
- Search tree consists of two types of nodes
- Your move (squares), Max nodes : goal is to maximize the value of the child
of that node (choose child with greatest value)
- Opponent move (circles), Min nodes : goal is to minimize the value of the
child of that node (choose child with least value)
- Extension of Depth First Search
- Assumption : Max starts the game
Minimax Algorithm
1. The start node is Max node with current board configuration
2. Expand nodes down to some depth of look-ahead in the game
3. Apply evaluation function at each of the leaf nodes
4. Back up values for each non-leaf nodes until computed for the root node
5. At Min nodes, the backed up value is the minimum of the values associated
with its children
6. At Max nodes, the backed up value is maximum of the values associated
with its children
Minimax Algorithm (Limitations)
1. Not complete if depth is infinite
2. Time increases exponentially with the depth of tree
Alpha Beta Pruning
- Seeks to decrease no of nodes evaluated by minimax algorithm in search
tree
- Stops evaluating a move when at least one possibility has been found that
proves the move to be worse than a previously examined move
- Prunes away the branches in minimax search tree that does not influence
the final decision
Alpha Beta Pruning
- Two bounds (alpha and beta) are passed along that restrict the set of
possible solutions
- Alpha : lower bound on the value that a maximizing node may ultimately be
assigned
- Beta : upper bound on the value that a minimizing node may be assigned
- Max node has a alpha value which never decreases and Min node has a beta
value which never increases
End of Chapter 3

Searching Algorithm

  • 1.
    Search Techniques By -Er. Suraj Awal
  • 2.
    - Uninformed Search(BFS, DFS, DLS) - Informed Search (Hill Climbing, Simulated Annealing, Best First Search, Greedy Search, A*, Minimax, Alpha Beta Pruning) - Evaluation of Search Strategy Inside the Box
  • 3.
    Searching - Searching isthe process of finding the goal state from its current state in a state space using a successor function; ultimately generating a solution for a problem. - Initially, V = {S}, where S is the initial state. When S is expanded, its successor are generated and those nodes are added to V and the associated arcs are added to E. This process continues until a goal node is found.
  • 4.
    Uninformed Search - Blindsearch - Information about the problem definition only - No additional information about the state space - Typically visits all the nodes of a tree in certain order looking for a goal - Able to expand current state to get a new set of states - Able to distinguish goal state from non-goal state. - Less effective - Example : Breadth First Search (BFS), Depth First Search (DFS) and Depth Limit Search (DLS)
  • 5.
    Breadth First Search -Proceeds level by level down the search tree - Starting from the root node, it explores all the children from left to right - If no solution is found, expands leftmost child of root node, then expands second node at same depth and so on.
  • 6.
    Breadth First Search(Algorithm) 1. Place the start node at the end of the queue 2. Examine the node at the start of the queue a) If the queue is empty, stop b) If the node is goal node, stop c) Else, add the children of the node at the end of the queue 3. Repeat step 2
  • 7.
    Depth First Search -Proceeds down a single branch at a time - Expands root node, then leftmost child and so on until the deepest level
  • 8.
    Depth First Search(Algorithm) 1. Place the start node at the end of the stack 2. Examine the node at the end of the stack a) If the stack is empty, stop (No solution) b) If the node is goal node, stop (Solution found) c) Else, add the children of the node at the end of the stack 3. Repeat step 2
  • 9.
    Depth Limit Search -Same as Depth first search - But the depth limit is specified to level ‘l’
  • 10.
    Properties of UninformedSearch Algorithms Time Complexity? Space Complexity? Complete? Minimal? BFS O(bd+1) O(bd) Yes Yes DFS O(bd+1) O(b*d) No No DLS O(bl+1) O(b*l) No No
  • 11.
    Informed Search - Heuristicsearch - Heuristic is a technique designed to solve a problem quickly - Information about the problem definition along with specific problem knowledge - Evaluate which of the nodes on frontier are more promising - Develop domain specific heuristic function h(n) that guesses the cost of getting to the goal from node n - Eg : Best first search, Hill climbing, Simulated annealing, A*, and so on.
  • 12.
    Hill Climbing Algorithm -Used for mathematical optimization problems in the field of AI - Variant of Depth first search that selects the next node based on estimate of heuristic - Practical Examples : n Queens, Toy problem
  • 13.
    Hill Climbing Algorithm 1.Evaluate the initial state. If it is the goal state, then stop. Else, make initial state as current state 2. Expand the current state 3. Choose the state that have good fitness than current state and make that state as current state 4. Repeat from step 2 until solution is found or there are no new states that can be applied to current state.
  • 14.
    Hill Climbing Algorithm(Problems) 1. Local maxima (Backtracking) 2. Plateau (Big jump) 3. Ridge (Bi-directional search)
  • 15.
    Simulated Annealing - Justlike hill climbing algorithm - Allows downhill step to escape local maxima - Uses a control parameter T, that is high at starting and gradually decreases towards 0 - A bad move from A to B [ f(A) > f(B) ] is accepted with probability: P = e ( f(B) - f(A) ) / T - Higher T, likelihood of making bad move is high - As T tends to 0, P tends to 0. It means, it acts as hill climbing algorithm
  • 16.
    Greedy Search - Triesto get as close as it can to the goal - Expands the node that is closest to the goal - Evaluation function : f(n) = h(n) - It does not guarantee solution (May trap in the loop) - It is not optimal
  • 17.
    Greedy Search (Algorithm) 1.Initialize current node as initial node 2. Is h(current_node) = 0? 3. If yes, return success 4. If no, a) Expand the node b) Assign the node with least f(n) or h(n) as current node 1. Repeat from step 2
  • 18.
    A* Search - Combinespath cost and heuristic to form evaluation function - f(n) = g(n) + h(n) - It is complete if h(n) is admissible or valid - It is optimal if h(n) is consistent or same
  • 19.
    A* Search 1. Initializecurrent node as initial node 2. Is h(current_node) = 0? 3. If yes, return success 4. If no, a) Expand the node b) Assign the node with least f(n) as current node : f(n) = g(n) + h(n) 1. Repeat from step 2
  • 20.
    Minimax Algorithm - Algorithmto find optimal move in a two player game - Search tree consists of two types of nodes - Your move (squares), Max nodes : goal is to maximize the value of the child of that node (choose child with greatest value) - Opponent move (circles), Min nodes : goal is to minimize the value of the child of that node (choose child with least value) - Extension of Depth First Search - Assumption : Max starts the game
  • 21.
    Minimax Algorithm 1. Thestart node is Max node with current board configuration 2. Expand nodes down to some depth of look-ahead in the game 3. Apply evaluation function at each of the leaf nodes 4. Back up values for each non-leaf nodes until computed for the root node 5. At Min nodes, the backed up value is the minimum of the values associated with its children 6. At Max nodes, the backed up value is maximum of the values associated with its children
  • 22.
    Minimax Algorithm (Limitations) 1.Not complete if depth is infinite 2. Time increases exponentially with the depth of tree
  • 23.
    Alpha Beta Pruning -Seeks to decrease no of nodes evaluated by minimax algorithm in search tree - Stops evaluating a move when at least one possibility has been found that proves the move to be worse than a previously examined move - Prunes away the branches in minimax search tree that does not influence the final decision
  • 24.
    Alpha Beta Pruning -Two bounds (alpha and beta) are passed along that restrict the set of possible solutions - Alpha : lower bound on the value that a maximizing node may ultimately be assigned - Beta : upper bound on the value that a minimizing node may be assigned - Max node has a alpha value which never decreases and Min node has a beta value which never increases
  • 25.