Blind Search
Blind Search
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
*Search algorithm
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
Quality of the Solution: It is important to note that the solution produced by the
BFS algorithm is not guaranteed to be optimal.
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
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
UCS 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.
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)
There is some variants of DFS algorithm that perform well than DFS:
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)