0% found this document useful (0 votes)
2 views

AIML Lec-4-6

Uploaded by

shubhodippal01
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)
2 views

AIML Lec-4-6

Uploaded by

shubhodippal01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Artificial Intelligence

& Machine Learning


Dr. Sankhadeep Chatterjee
Searching Problem: Travelling in Romania
Searching Problem:
Travelling in Romania
 On holiday in Romania; currently in Arad.

 Flight leaves tomorrow from Bucharest

 Formulate goal: be in Bucharest

 Formulate problem:
⚫ states: various cities
⚫ actions: drive between cities

 Find solution:
⚫ sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
Travelling in Romania

Start State

Goal State
Problem Formulation

 initial state: at Arad

 successor function S(x) = set of action-state pairs


⚫ e.g., S(Arad) = <Arad → Zerind-Zerind>

 goal test : at Bucharest

 path cost (additive) : sum of distances

 A solution is a sequence of actions leading from the initial


state to a goal state
State Space Search (Tree Search)
Tree Search
Tree Search
Tree Search Algorithm

 Basic idea:

 offline, simulated exploration of state


space

 by generating successors of already-


explored states

 (a.k.a. expanding states)


Tree Search Algorithm
Search strategies
 A strategy is defined by picking the order of node expansion

 Strategies are evaluated along the following dimensions:


⚫ Completeness: does it always find a solution if one exists?
⚫ Time complexity: number of nodes generated/expanded
⚫ space complexity: maximum number of nodes in memory
⚫ Optimality: does it always find a least-cost solution?

 Time and space complexity are measured in terms of


⚫ b: maximum branching factor of the search tree
⚫ d: depth of the least-cost solution
⚫ m: maximum depth of the state space (may be ∞)
Uninformed Search

 Uninformed strategies use only the


information available in the problem
definition
⚫ Breadth-first search
⚫ Uniform-cost search
⚫ Depth-first search
⚫ Depth-limited search
⚫ Iterative deepening search
Breadth-first search

 Expand shallowest unexpanded node


 Fringe: nodes waiting in a Queue to be
explored, also called OPEN
 Implementation:
⚫ For BFS, fringe is a first-in-first-out (FIFO) queue
⚫ new successors go at end of the queue
 Repeated states?
⚫ Simple strategy: do not add parent of a node as
a leaf
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
Breadth-first search
1. If start node is goal node return success
2. Put the start node ‘s’ on OPEN
3. If OPEN is empty exit with failure.
4. Remove the first node ‘n’ from OPEN and place it on
CLOSED.
5. Expand ‘n’, Do for all successors –
1. If child is not in CLOSED or OPEN, then
1. If child is goal node, then return success
2. Else add child at the end of OPEN.
6. Go to step 4
Example: Map Navigation

State Space:
S = start, G = goal, other nodes = intermediate states, links = legal transitions

A B C

S G

D E F
BFS Search Tree
A B C

S G
S
D E F

Queue = {S}

Select S

Goal(S) = true?

If not, Expand(S)
BFS Search Tree
A B C

S G
S
D E F
A D

Queue = {A, D}

Select A

Goal(A) = true?

If not, Expand(A)
BFS Search Tree
A B C

S G
S
D E F
A D

B D Queue = {D, B, D}

Select D

Goal(D) = true?

If not, expand(D)
BFS Search Tree
A B C

S G
S
D E F
A D

B D A E Queue = {B, D, A, E}

Select B
etc.
BFS Search Tree
A B C

S G
S
D E F
A D

B D A E

C E S E S B B F

Level 3
Queue = {C, E, S, E, S, B, B, F}
BFS Search Tree
A B C

S G
S
D E F
A D

B D A E

C E S E S B B F

D F A B F D C E A C G

Level 4
Expand queue until G is at front
Select G
Goal(G) = true
Breadth-first search

 Time Complexity

⚫ Assume (worst case) that


there is one goal leaf (G) at
the RHS
⚫ So BFS will expand all nodes
= 1 + b + b2+ ......... + bd
= O(bd)
Breadth-first search

 Space Complexity

⚫ How many nodes can be in


the queue (worst-case)?

⚫ At depth d there are bd


unexpanded nodes in the
Queue
= O(bd)
Depth-first Search

 Expand deepest unexpanded node

 The fringe is a LIFO queue i.e. Stack


Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first Search
Depth-first search

 Time Complexity

⚫ Assume (worst case) that


there is one goal leaf (G) at
the RHS
⚫ So BFS will expand all nodes
= 1 + b + b2+ ......... + bm
= O(bm)
Depth-first search

 Space Complexity

⚫ how many nodes can be in


the queue (worst-case)?

⚫ O(bm) if deepest node at


depth m (maximum
depth)
Uniform Cost Search
 BFS except: Expand lowest cost node
Iterative-Deepening

 Implements BFS with DFS

 Every iteration is a DFS with a depth


cutoff.
Iterative-Deepening

 Limit = 1
 While no solution, do
⚫ DFS from initial state ‘S’ with cutoff Limit
⚫ If found goal,
• stop and return solution
⚫ else
• increment cutoff
Iterative-Deepening Example
Iterative-Deepening Example
Iterative-Deepening Example
Iterative-Deepening Example
Bi-directional Search

 Idea

⚫ simultaneously search forward from S


and backwards from G
⚫ stop when both “meet in the middle”
⚫ need to keep track of the intersection
of 2 open sets of nodes
Bi-directional Search

 Complexity

⚫ time complexity is best:


O(2 b(d/2))
= O(b(d/2))

⚫ memory complexity is the same


Summary
Time and space complexity are measured in terms of

b: maximum branching factor of the search tree


d: depth of the least-cost solution
m: maximum depth of the state space (may be ∞)

Breadth Depth First Iterative Bi-directional


First Search Search Deepening Search
Time
O(bd) O(bm) O(bd) O(b(d/2))
Complexity
Space
O(bd) O(bm) O(bd) O(b(d/2))
Complexity
Thank You

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy