0% found this document useful (0 votes)
26 views10 pages

Blind Search

The document introduces blind search algorithms, focusing on Breadth-First Search (BFS), Uniform Cost Search (UCS), and Depth-First Search (DFS). It details their definitions, algorithms, performance metrics such as completeness, optimality, and time and space complexities. Additionally, it compares these algorithms and discusses variations like Depth-Limited Search (DLS) and Iterative Deepening Depth-First Search (IDDFS).

Uploaded by

ss9234618
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)
26 views10 pages

Blind Search

The document introduces blind search algorithms, focusing on Breadth-First Search (BFS), Uniform Cost Search (UCS), and Depth-First Search (DFS). It details their definitions, algorithms, performance metrics such as completeness, optimality, and time and space complexities. Additionally, it compares these algorithms and discusses variations like Depth-Limited Search (DLS) and Iterative Deepening Depth-First Search (IDDFS).

Uploaded by

ss9234618
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/ 10

Blind Search

Blind Search (Recherche aveugle)


In this section, we introduce the basic machinery needed for search. We devise
algorithms for navigating the implicit search space and look at their properties, and we
began with a special family of algorithm that share a common feature. they are all
blind or uninformed.

A blind or uninformed search is utilized by a goal-based agent when it lacks any


additional information about the goal to be achieved, other than what is specified in
the problem formulation.

Breadth First Search


Definition
Breadth-first search is a straightforward strategy in which the root node is expanded
first. After that, all the successors of the root node are expanded next, followed by
their successors, and so on. In general, all nodes at a given depth in the search tree
are expanded before any nodes at the next level are processed.

Example
Let consider the tiny search problem that have seven nodes including the start one S
and the goal node G. The other nodes are named A, B, C, D, and E.

C
A
B

G
E

Problem formulation

States: The state space is formed by 7 nodes named respectively


{S, A, B, C, D, E, G}
Initial state: The initial state is chosen to be the state S
Actions: The allowed action in our environment is move to
Test goal achievement: If the move to action leads our agent to the state G then
the goal is reached.
Cost path: the cost path is the accumulated steps in the considered path.

*Search algorithm

Algorithm Breadth first search


procedure breadtFirstSearch(S )
if goalTest(S.state) then
return S
end if
Frontier ← S
Explored ← [ ]
while Frontier = ​  Empty do
child ← popQueue(Frontier)
if child ∈ Explored then
continue
else
Explored ← [child]
Nodes ← expand(child)
for n ∈ Nodes do
if n ∈ Frontier then
continue
else
if goalTest(n.state) then
return reconstructPath(n)
end if
pushQueue(Frontier,n)
end if
end for
end if
end while
return F ailure
end procedure

When we apply this algorithm to the tiny problem the search tree become like below:

{S} {} 1 1 1

{A,B,C} {S}
A 2 B C
{B,C,D} {S,A}

{C,D} {S,A,B} 2 4
3
{D} {S,A,B,C}
D G
Performance of the Breadth-First Search algorithm

Completeness: If a solution exists, the Breadth-First Search (BFS) algorithm will


find it.
Spatial Complexity: Assuming the goal state is located at a depth ( d ) and the
environment has a finite branching factor b, the worst-case scenario requires
storing all data needed to locate the goal state. In this case, the memory
requirement is proportional to b d units. Thus, the spatial complexity is O(b d ).
Temporal Complexity: The time complexity is also O(b d ).

For b = 10 the spatial and temporal complexity is estimated as below:

Quality of the Solution: It is important to note that the solution produced by the
BFS algorithm is not guaranteed to be optimal.

Uniform Cost Search algorithm


Definitions
Uniform Cost Search (UCS) algorithm is an optimal search algorithm used in
problem-solving. It expands the node with the lowest cumulative cost from the
starting state, which helps ensure that the total path cost is minimized. UCS utilizes a
priority queue organized by path cost and guarantees finding the least-cost solution,
provided that all costs are non-negative.

A priority queue is a data structure that holds elements together with their associated
priorities. In this structure, elements with higher priority are removed before those with
lower priority. When used in search algorithms, a priority queue ensures that the next
node to be expanded is the one with the highest priority, typically the one with the
lowest cost in pathfinding problems.

Example
Let consider now another problem like the one given below:
G

Problem formulation

States: The state space is formed by the white cells.


Initial state: is given by the green cell labeled with S .
Actions: {↑, ↓ ←, →}
Test Goal State: if the agent reaches the red cell labeled with G then the task is
accomplished.
s
Path cost: f(s) = ∑ n steps
s ′ =S

Search for solution


36 35 34 33 32 31 30 29 28 29 30 32 32 33 34 35 36 37

33 27 33

14 15 16 34 35 36 26 40 34 40 41 G
13 17 25 39 35 39

12 18 19 20 21 22 23 24 38 37 36 37 38

11 21 39

10 11 12 22 40

9 23 41

8 30 24

7 29 25

6 28 27 26

5 29

4 30

3 31

2 32 33 34

1 33

S 34

35

The solution is a sequence of actions :{14 ↑, 2 →, 2 ↓, 6 →, 4 ↑, 4 →, 4 ↓, 2 →, 2 ↑, 1 →}

UCS Algorithm

Algorithm Uniform cost search algorithm


procedure uniformCostSearch(S )
if goalTest(S.state) then
return S
end if
pushPriorityQueue(Frontier, S)
Explored ← [ ]
while Frontier = ​ Empty do
child ← popPriorityQueue(Frontier)
if child ∈ Explored then
continue
else
Explored ← Explored + +[child]
Nodes ← expand(child)
for n ∈ Nodes do
if inFrontier(n) or isLeaf(n) then
n.Parent.State ← Null
continue
else
if goalTest(n.state) then
return reconstructPath(n)
end if
pushPriorityQueue(Frontier,n)
end if
end for
end if
end while
return F ailure
end procedure

Performance of the Uniform-cost Search algorithm

Completeness
UCS is complete.
If a solution exists, UCS will find it, provided that the graph is finite and the
cost of each step is non-negative.
If the graph is infinite, UCS may not terminate if no solution exists.
Quality of the solution
UCS is optimal.
It guarantees the lowest-cost path to the goal, assuming all edge costs are
non-negative.
This is because UCS always expands the node with the lowest path cost first,
ensuring that the first time the goal is reached, it is via the lowest-cost path.
Space Complexity
The space complexity of UCS is
C∗
O(b d+⌊ ϵ

)

This is because UCS stores all explored nodes in memory (in the priority
queue).
Like time complexity, the space complexity is exponential in the worst cases.
Time Complexity
The time complexity of UCS depends on the number of nodes and edges in the
graph.
Let:
b = branching factor (average number of successors per node).
C ∗ = cost of the optimal solution.
ϵ = minimum edge cost.
The time complexity is
C∗
O(b d+⌊ ϵ ⌋
)
This is because UCS explores all nodes with a path cost less than or equal to
C ∗.
In the worst case, it explores all nodes in the graph, leading to exponential
time complexity.
Key Factors Affecting Performance
Graph Size: Larger graphs increase the number of nodes and edges to
explore, leading to higher time and space requirements.
Branching Factor b: Higher branching factors increase the number of nodes to
explore, making the algorithm slower and more memory-intensive.
Cost Structure: If the optimal path cost C ∗ is large relative to the minimum
edge cost ϵ, the algorithm will explore more nodes.

Depth First Search algorithm


We define the frontier data structure as a stack, where elements are retrieved from the
top. Candidates generated by the Expand procedure are added to this Last In, First
Out (LIFO) structure. The search space resembles a tree, and with each iteration, a
new branch is created. The Depth-First Search (DFS) algorithm explores the search
tree in a non-linear manner, delving into a branch until it reaches its endpoint before
returning to the root to investigate another branch.

Algorithm Depth-First Search algorithm


procedure depthFirstSearch(S )
Frontier ← [S]
Explored ← [ ]
while Frontier = ​  Empty do
Node ← popStack(Frontier)
if inExplored(Node) then
continue
else
if goalTest(Node.State) then
return reconstructPath(Node)
else
Explored ← Node
for Child in Expand(Node) do
if inFrontier(Child) then
continue
else
pushStack(Frontier,Childs)
end if
end for
end if
end if
end while
return Failure
end procedure

*Performance Analysis of Depth-First Search algorithm

Completeness
In general, DFS is not complete because of infinite or cyclic graphs
It may get stuck in an infinite loop if the graph contains cycles and no goal
node is reachable.
In finite graphs, DFS is complete because it will eventually explore all nodes.
But under some modification (to avoid cyclic behavior) and condition (finite
graph) it will becomes complete.
Quality of the solution
DFS is not optimal.
It does not guarantee the shortest path (in unweighted graphs) or the lowest-
cost path (in weighted graphs).
The first solution found may not be the best one
4. Space Complexity
The space complexity is

O(bd)

DFS only needs to store the current path from the root to the leaf node.
In the worst case, it stores d nodes (depth of the tree).
This makes DFS more memory-efficient than Breadth-First Search (BFS) for
deep trees.
Time Complexity
Let:
b the branching factor (average number of successors per node).
d the maximum depth of the search tree.
The time complexity is

O(b d )

In the worst case, DFS explores all possible paths up to depth d before finding
the goal.
For a graph with V nodes and E edges, the time complexity is

O(V + E)

when using an adjacency list representation.


Key Factors Affecting Performance
Graph Structure:
DFS performs well on graphs with shallow solutions or when the goal is
deep in the tree.
It can perform poorly on graphs with infinite branches or cycles.
Branching Factor b:
Higher branching factors increase the number of nodes to explore, but
DFS only stores the current path.
Depth of the Tree d:
DFS is efficient for deep trees with small branching factors.

There is some variants of DFS algorithm that perform well than DFS:

Depth-Limited Search algorithm (DLS ) is a variation of Depth-First Search (DFS)


designed to overcome one of its main drawbacks: the potential for exploring
infinite paths. DLS introduces a depth limit, denoted as L, which restricts how
deep the algorithm can go from the starting node. This limitation makes DLS
complete for graphs with finite depth and helps prevent infinite loops in graphs
that are infinite.
Iterative deepening depth-first search (IDDFS) is a hybrid search algorithm that
combines the advantages of Depth-First Search (DFS) and Breadth-First Search
(BFS). It conducts a series of Depth-Limited Searches (DLS) with progressively
increasing depth limits, starting from 0 and incrementing until the goal is located.

Comparison of blind search algorithms

Algorithm Completeness Optimality Time Space


Complexity Complexity
Depth-First No No O(b d ) O(bd)
Search (DFS)
Algorithm Completeness Optimality Time Space
Complexity Complexity
Breadth-First Yes Yes (for O(b d ) O(b d )
Search (BFS) unweighted
graphs)
Uniform Cost Yes Yes O(b d+⌊
C∗
ϵ

) O(b d+⌊
C∗
ϵ

)
Search (UCS)

Exercise
Solve the below 8-puzzle problem using the Uniform Cost Search (UCS) algorithm
first, followed by the Depth-Limited Search (DLS) algorithm.

PYTHON

import numpy as np
import random

random.seed(1)
puzzle = np.asarray(range(9))
np.random.shuffle(puzzle)
puzzle = puzzle.reshape((3,3))
print(puzzle)

You might also like