You are on page 1of 67

Artificial Intelligence

Search Techniques -
Uninformed Search
Searching for Solution

After formulating our problem we are ready to solve it, this


can be done by searching through the state space for a
solution, this search will be applied on a search tree or
generally a graph that is generated using the initial state
and the successor function.
Searching is applied to a state space which is generated
through state expansion, that is applying the successor
function to the current state, note that here we mean by
state a node in the search tree.
Generally, search is about selecting an option and putting
the others aside for later in case the first option does not
lead to a solution, The choice of which option to expand first
is determined by the search strategy used.
Searching

Searching through a state space involves the following:


❖ A set of states

❖ Operators and their costs

❖ Start state

❖ A test to check for goal state


The search problem is to find a sequence of actions
which transforms the agent from the initial state to a
goal state g∈G. A search problem is represented by a
4-tuple {S, s0, A, G}.
❖ S: set of states

❖ s0 ∈ S : initial state

❖ A: S🡪 S : operators/ actions that transform one

state to another state


❖ G : goal, a set of states. G ⊆ S
Generic Search process

The generic searching process can be very simply


described by the following steps:
Generic Search process: Example

s0 is the initial state.


The successor states
are the adjacent states
in the graph.
There are three goal
states
Generic Search process: Example
Generic Search process: Example
Generic Search process: Example
Generic Search process: Example

This example
illustrates how we can
start from a given
state and follow the
successors, and be
able to find solution
paths that lead to a
goal state.
Graph Search

The graph describes the search (state) space


❖ each node in the graph represents one state in the search

space e.g. a city to be visited in a routing or touring


problem
This graph has additional information
❖ names and properties for the states (e.g. S, 3)

❖ links between nodes, specified by the successor function

properties for links


A
(distance,
1 cost, name,
D
...)
4 3

1 1 1 3

S 5 C 2 G
3 2 0

1 3 3 4
B E
2 1
2
Graph and Tree

The tree is generated by traversing the graph the same node


in the graph may appear repeatedly in the tree the
arrangement of the tree depends on the traversal strategy
(search method)
The initial state becomes the root node of the tree in the fully
expanded tree, the goal states are the leaf nodes cycles in
graphs may result in infinite branches
S
3
A 1 D 1 5 1
4 3
A C B
4 2 2
1 1 1 3
1 1 1 1 2 3 3 2

S 5 C 2 G D C D G E C E
3 2
2 0 3 2 3 0 1 2
4
1

3 1 2 3 3 4 1 2 3 4

1 3 3 4 G D G E G G D G E G
0 3 0 1 0 0 3 0 1 0
B E
3 4 3 4
2 1
G G G G
0 0 0 0
Searching for Solution

The structure of a node in the search tree can be as


follows:
❖ State: the state in the state space to which this

state corresponds
❖ Parent-Node: the node in the search graph that

generated this node.


❖ Action: the action that was applied to the parent to

generate this node.


❖ Path-Cost: the cost of the path from the initial

state to this node.


❖ Depth: the number of steps along the path from

the initial state.


Searching for Solution

It is important to make a distinction between


nodes and states. A node in the search tree is a data
structure holds a certain state and some info used to
represent the search tree, where state corresponds to a
world configuration, that is more than one node can
hold the same state, this can happen if 2 different
paths lead to the same state.
Properties of Search Strategies

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 measured in terms of


❖ Maximum branching factor (b) of the

search tree
❖ Depth (d) of a solution with minimal
Uninformed Search
Uninformed Search

❖ An uninformed (a.k.a. blind, brute-force) search


algorithm generates the search tree without using
any domain specific knowledge.
❖ No additional information about states beyond that
provided in the problem definition.
❖ All they can do is generate successors and
distinguish a goal state from a non-goal state.
❖ All search strategies are distinguished by the order
in which nodes are expanded.
❖ Key idea is Move systematically between states until
we stumble on a goal

Types of Uninformed Search

Uninformed Search
1. Breadth-First Search (BFS)
2. Depth-First Search (DFS)
3. Depth-Limited Search (DLS)
4. Iterative-Deepening Search (IDS)
5. Uniform-Cost Search (UCS)
6. Bidirectional Search (BDS)
Breadth-First Search

❖ Breadth-First Search (BFS) uses a queue (or FIFO)


to support search of most recently unexplored
nodes first.
❖ BFS always expands the shallowest unexpanded
node.
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search
Breadth-First Search

State space graph Search tree for the state space


graph

A state space graph and its equivalent search tree is


Breadth-First Search

Fringe: A Fringe: B C
Breadth-First Search

Fringe: C D E Fringe: D E D G
Breadth-First Search

Fringe: E D G C F Fringe: D G C F
Breadth-First Search

Fringe: G C F B F
Node G is expanded and found to be a goal node. The
solution path A--C--G is returned and the algorithm
terminates.
Breadth-First Search
Depth-First Search

In depth-first search, we start with the root node and


completely explore the descendants of a node before
exploring its siblings (and siblings are explored in a
left-to-right fashion).
Depth-first search always expands the deepest node in
the current frontier of the search tree.
We use a stack to implement DFS search.
Depth-First Search
Depth-First Search

State space graph Search tree for the state space


graph

A state space graph and its equivalent search tree is


Depth-First Search

Fringe: A Fringe: B C
Depth-First Search

Fringe: D E C Fringe: C F E C
Depth-First Search

Fringe: G F E C

Node G is expanded and found to be a goal node. The


solution path A-B-D-C-G is returned and the algorithm
terminates.
Depth-First Search
Depth Limited Search

The embarrassing failure of depth-first search in


infinite state spaces can be alleviated by supplying
depth-first search with a predetermined depth limit.
That is, nodes at particular depth are treated as if they
have no successors. This approach is called
depth-limited search. The depth limit solves the
infinite-path problem.
Depth-limited search can be implemented as a simple
modification to the general tree or graph-search
algorithm.
Notice that depth-limited search can terminate with
two kinds of failure: the standard failure value
indicates no solution; the cutoff value failure
Depth Limited Search
Depth Limited Search

Start state is A and Goal state is O


Depth Limited Search
Depth Limited Search
Depth Limited Search
Depth Limited Search
Depth Limited Search
Iterative Deepending Search

It’s a Depth First Search, but it does it one level at a


time, gradually increasing the limit, until a goal is
found.
Combine the benefits of depth-first and breadth-first
search
like DFS, modest memory requirements O(bd)
like BFS, it is complete when branching factor is finite,
and optimal when the path cost is a non decreasing
function of the dept of the node
Many states are expanded multiple times but it doesn’t
really matter because the number of those nodes is
small in practice and hence it is one of the best
Iterative Deepening Search or
Depth-First Iterative Deepening (DFID)

First do DFS to depth 0 (i.e., treat start node as having


no successors), then, if no solution found, do DFS to
depth 1, and so on till the solution is found.
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Evaluation of Iterative Deepening Search
Uniform Cost Search

In uniform cost search the newly generated nodes are


put in OPEN/fringe according to their path costs. This
ensures that when a node is selected for expansion it is
a node with the cheapest cost among the nodes in
OPEN/fringe.
Let g(n) = cost of the path from the start node to the
current node n. Sort nodes by increasing value of g.
Uniform Cost Search is
❖ Complete

❖ Optimal/Admissible
d
❖ Exponential time and space complexity, O(b )
Uniform Cost Search

State space graph Search tree for the state


space graph
Uniform Cost Search

Function UCS( )
Insert the root into the queue
While the queue is not empty
Dequeue the maximum priority element from the
queue
(If priorities are same, alphabetically smaller path is
chosen)
If the path is ending in the goal state, print the path
and exit
Else
Insert all the children of the dequeued element,
with
Uniform Cost Search

Initialization: { [ S , 0 ] }
Iteration 1: { [ S->A , 1 ] , [ S->G , 12 ] }
Iteration 2: { [ S->A->C , 2 ] , [ S->A->B , 4 ] , [ S->G ,
12] }
Iteration 3: { [ S->A->C->D , 3 ], [ S->A->B , 4 ], [
S->A->C->G , 4 ], [ S->G , 12 ] }
Iteration 4: { [ S->A->B , 4 ] , [ S->A->C->G , 4 ] , [
S->A->C->D->G , 6 ] , [ S->G , 12 ] }
Iteration 5: { [ S->A->C->G , 4 ] , [ S->A->C->D->G , 6 ] , [
S->A->B->D , 7 ] , [ S->G , 12 ] }
Iteration 6: gives the final output as S->A->C->G.
Bidirectional Search

When the start and goal nodes are known, the


bidirectional search (BDS) can be used.
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.
Bidirectional Search

The search stops when these two graphs intersect each


other.
Bidirectional search can use search techniques such as
BFS, DFS, DLS, etc.
The idea behind BDS is to run two search algorithms
(e.g., BFS, O(b^d)) simultaneously, namely one
forward from the initial state and the other backward
from the goal - hoping that the two searches meet in
the middle.
The motivation is that b^d/2 + b^d/2 is much less
than b^d
Bidirectional Search

❖ BDS is implemented by replacing the goal test with a


check to see whether the frontiers of the two searches
intersect; if they do, a solution has been found.
❖ The time complexity of BDS using breadth-first
searches in both directions is O(b^d/2).
❖ The space complexity of BDS is also O(b^d/2).
❖ When the two paths meet at a common node, a
complete and optimal solution path is found.
❖ A major disadvantage of BDS is that BDS requires
knowledge of the goal node. The goal node is the
most commonly desired node in search, and is
therefore not commonly known a priori.
Bidirectional Search
1. F1 : S = {A}, B1 : T = {N}
Decide to go to Step 3.
2. F2 : S = {A, B, C}.
B2: T={N, M, L}
S ⋂ T=NULL
F3:S={A, B, C, D,E, F}
B3: T={N, M, L,I, J,K}
S ⋂ T=NULL
F4:S={A, B, C, D,E, F,G,H}
B4: T={N, M, L,I, J,K,G,H}
S ⋂ T={G,H} Stop .
The solution solution path is
(A→ B→ E→H→ J → L → N)
Problem in Bidirectional Search

Problem: how do we search backwards from goal??


❖ predecessor of node n = all nodes that have n as

successor
❖ This may not always be easy to compute!

❖ If several goal states, apply predecessor function to

them just as we applied successor (only works well if


goals are explicitly known; may be difficult if goals
only characterized implicitly).
❖ For bidirectional search to work well, there must be

an efficient way to check whether a given node


belongs to the other search tree.
❖ – select a given search algorithm for each half.
Bidirectional Search
Comparing Search Strategies

Evaluation of tree-search strategies. b is the branching


factor; d is the depth of the shallowest solution; m is the
maximum depth of the search tree; l is the depth limit.
Superscript caveats are as follows: a complete if b is finite; b
complete if step costs ≥ for positive ; c optimal if step costs are all
identical; d if both directions use breadth-first search.
Thank You!!

You might also like