CS414-Artificial Intelligence: Lecture 5: Basic Search Algorithms
CS414-Artificial Intelligence: Lecture 5: Basic Search Algorithms
)
Space Complexity: O(b)
Optimal: No.
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 36 / 48
An Example
Figure : DLS example with different depth limit
Home Work
Given the map of Romania, what will be the minimum depth limit
and generate graphs using DLS based on your reported for:
From Arad to Busharest.
From Iasi to Zerind.
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 37 / 48
Outline
1
Basic search algorithms
2
Infrastructure for Search Algorithms
3
Search Strategy
4
Uninformed Search Algorithms
Breadth-First Search
Uniform-cost search
Depth-rst search
Depth-limited Search
Iterative Deepening Search
5
Informed Search
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 38 / 48
Iterative Deepening Search
Reading
Read it by your self and solve the above problem for IDS as well.
You are also supposed to read Bidirectional Search.
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 39 / 48
Outline
1
Basic search algorithms
2
Infrastructure for Search Algorithms
3
Search Strategy
4
Uninformed Search Algorithms
Breadth-First Search
Uniform-cost search
Depth-rst search
Depth-limited Search
Iterative Deepening Search
5
Informed Search
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 40 / 48
Informed Search
What we have seen so far are all those search algorithms that
operate with out any domain knowledge, and try to solve the
problem in brute-force fashion.
Such methods are insufcient for most problems specially when
the problem is large and complex.
Now we will look into another type of search techniques called
informed search.
Denition
Informed Search Incorporates a heuristic in the search that determines
the quality of any state in the search space. In a graph search, this
results in a strategy for node expansion. The heuristic may consider
the problem knowledge to guide the search strategy.
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 41 / 48
Best First Search I
In Best-FS state space is evaluated on the basis of an evaluation
function f (n) that incorporates a heuristic function h(n) and
estimated cost g(n) from start node to n, i.e., f (n) = h(n).
This search strategy is also called A* Search.
The h(n) can be an educated guess such that the cheapest path
from the state at node n to the goal.
In Romania example, this may be a straight line between state at
node n to goal.
The g(n) is the cost from the start node to node n.
The algorithm is often implemented by maintaining two list, an
open one and a closed one.
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 42 / 48
Best First Search II
Open list is a priority queue consist nodes yet to be visited sorted
by their evaluation function.
Closed list contains nodes that have already been evaluated.
Best-FS specializes to BFS when f (n) = h(n) and to UFS when
f (n) = g(n).
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 43 / 48
An Example
Consider again the Romania example
Bucharest
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
Dobreta
Craiova
Sibiu
Fagaras
Pitesti
Rimnicu Vilcea
Vaslui
Iasi
Straightline distance
to Bucharest
0
160
242
161
77
151
241
366
193
178
253
329
80
199
244
380
226
234
374
98
Giurgiu
Urziceni
Hirsova
Eforie
Neamt
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
Dobreta
Craiova
Sibiu
Fagaras
Pitesti
Vaslui
Iasi
Rimnicu Vilcea
Bucharest
71
75
118
111
70
75
120
151
140
99
80
97
101
211
138
146 85
90
98
142
92
87
86
Figure : Romania map with SLD
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 44 / 48
Greedy Fashion
Rimnicu Vilcea
Zerind
Arad
Sibiu
Arad Fagaras Oradea
Timisoara
Sibiu Bucharest
329 374
366 380 193
253 0
Rimnicu Vilcea
Zerind
Arad
Sibiu
Arad Fagaras Oradea
Timisoara
329 374
366 176 380 193
Zerind
Arad
Sibiu Timisoara
253 329 374
Arad
366
(a) The initial state
(b) After expanding Arad
(c) After expanding Sibiu
(d) After expanding Fagaras
Figure : In the greedy fashion
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 45 / 48
A* Search Example
(a) The initial state
(b) After expanding Arad
(c) After expanding Sibiu
Zerind
Arad
Sibiu Timisoara
447=118+329 449=75+374 393=140+253
Arad
366=0+366
(d) After expanding Rimnicu Vilcea
(e) After expanding Fagaras
(f) After expanding Pitesti
Zerind
Arad
Sibiu
Arad
Timisoara
Rimnicu Vilcea Fagaras Oradea
447=118+329 449=75+374
646=280+366 413=220+193 415=239+176 671=291+380
Zerind
Arad
Sibiu
Arad
Timisoara
Fagaras Oradea
447=118+329 449=75+374
646=280+366 415=239+176
Rimnicu Vilcea
Craiova Pitesti Sibiu
526=366+160 553=300+253 417=317+100
671=291+380
Zerind
Arad
Sibiu
Arad
Timisoara
Sibiu Bucharest
Rimnicu Vilcea Fagaras Oradea
Craiova Pitesti Sibiu
447=118+329 449=75+374
646=280+366
591=338+253 450=450+0 526=366+160 553=300+253 417=317+100
671=291+380
Zerind
Arad
Sibiu
Arad
Timisoara
Sibiu Bucharest
Rimnicu Vilcea Fagaras Oradea
Craiova Pitesti Sibiu
Bucharest Craiova Rimnicu Vilcea
418=418+0
447=118+329 449=75+374
646=280+366
591=338+253 450=450+0 526=366+160 553=300+253
615=455+160 607=414+193
671=291+380
Figure : The A* implementation
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 46 / 48
A* Search
A* Search Rating
Complete: Yes
Time Complexity: O(b
d
)
Space Complexity: O(b
d
)
Optimal: Yes.
A* search algorithm have two avors, the graph based and tree based.
Conditions for Optimality: Admissibility and Consistency
Admissibility: That the heuristic is admissible i.e., that h(n) will never
overestimate the cost to reach the goal. For A*, h(n) is admissible,
since straight line is the shortest path between any two points.
Consistent: Consistency (also called monotonicity) describes that the
cost along the path is increasing or decreasing. For A* graph version,
the g(n) is the increasing function of n along the path..
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 47 / 48
References I
Waheed Noor (CS&IT, UoB, Quetta) CS414-Articial Intelligence September-October 2014 48 / 48