Skip to main content
CSE 412: Artificial IntelligenceCSE 412: Artificial Intelligence
Fall 2018Fall 2018
Topic – 3: Solving ProblemsTopic – 3: Solving Problems
by Searchingby Searching
Tajim Md. Niamat Ullah Akhund
Lecturer
Department of Computer Science and Engineering
Daffodil International University
Email: tajim.cse@diu.edu.bd
Topic ContentsTopic Contents
Problem Solving AgentsProblem Solving Agents
Problem Formulation and Search SpacesProblem Formulation and Search Spaces
Example ProblemsExample Problems
Tree Search AlgorithmTree Search Algorithm
 Breadth-First SearchBreadth-First Search
 Uniform-Cost SearchUniform-Cost Search
 Depth-First SearchDepth-First Search
 Depth Limited SearchDepth Limited Search
 Iteratively Deepening SearchIteratively Deepening Search
 Bidirectional SearchBidirectional Search 2
IntroductionIntroduction
In this topic, we see how an agent can find
a sequence of actions that achieves its
goals, when no single action will do.
3
Majidur RahmanMajidur Rahman
Problem-SolvingProblem-Solving AgentAgent
Four general steps in problem solving:
• Goal formulation
– What are the successful world states
• Problem formulation
– What actions and states to consider given the goal
• Search
– Examine different possible sequences of actions that
lead to states of known value and then choose the
best sequence
• Execute
– Perform actions on the basis of the solution
4
Majidur RahmanMajidur Rahman
Example: RomaniaExample: Romania
5
Majidur RahmanMajidur Rahman
Example: RomaniaExample: Romania
On holiday the agent is in Romania visiting 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,…
6
Majidur RahmanMajidur Rahman
Problem TypeProblem Type
Given how we have defined the problem:
• Environment is fully observable
• Environment is deterministic
• Environment is sequential
• Environment is static
• Environment is discrete
• Environment is single-agent
7
Majidur RahmanMajidur Rahman
Problem FormulationProblem Formulation
A problem is defined by:
 An initial state, e.g. In(Arad)
 A successor function S(x) = set of action-state pairs
• S(In(Arad)) = {(Go(Sibiu), In(Sibiu)), (Go(Zerind), In(Zerind)),
(Go(Timisoara), In(Timisoara))}
• initial state + successor function = state space
 Goal test
• Explicit, e.g. x=‘In(Bucharest)’
 Path cost (assume additive)
• e.g. sum of distances, number of actions executed, …
A solution is a sequence of actions from initial to
goal state
 the optimal solution has the lowest path cost
8
Majidur RahmanMajidur Rahman
Vacuum WorldVacuum World
State space of the vacuum world
9
Majidur RahmanMajidur Rahman
Example ProblemsExample Problems
The problem-solving approach has been applied to
a vast array of task environments.
Some of the best known are listed here,
distinguishing between toy and real-world problems.
A toy problem is intended to illustrate or exercise
various problem-solving methods.
It is usable by different researchers to compare the
performance of algorithms.
 A real-world problem is one whose solutions
people actually care about.
We will mainly focus on toy problems in this topic.
10
Majidur RahmanMajidur Rahman
Toy Problems: 8-PuzzleToy Problems: 8-Puzzle
 States: location of each tile plus blank
 Initial state: Any state can be initial
 Actions: Move blank {Left, Right, Up, Down}
 Goal test: Check whether goal configuration is reached
 Path cost: Number of actions to reach goal
11
Majidur RahmanMajidur Rahman
Toy Problems: 8-QueensToy Problems: 8-Queens
Place eight queens on a chessboard such that
no queen attacks any other.
Two kinds of problem formulation:
• Complete-state formulation
• Incremental formulation
12
Majidur RahmanMajidur Rahman
Toy Problems: 8-QueensToy Problems: 8-Queens
Complete-state formulation
• States: Any arrangement of 0 to 8 queens on the board
• Initial state: No queens
• Actions: Add queen to any empty square
• Goal test: 8 queens on board and none attacked
• Path cost: N/A
64.63.62…..57 ≈ 3 x 1014
possible sequences to investigate
13Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund
Incremental formulation
• States: n (0 to 8) queens on the board, one per column in
the n leftmost columns with no queen attacking any other
• Actions: Add queen in leftmost empty column such that
the queen is not attacking any other queen
• 2057 possible sequences to investigate; solutions are
easy to find
But with 100 queens the problem is much harder
14
Toy Problems: 8-QueensToy Problems: 8-Queens
Real-World ProblemsReal-World Problems
 Route-finding problems
 Touring problems
 Traveling Salesman problem
 VLSI layout problem
 Robot navigation
 Automatic assembly sequencing
 Internet searching
15
Majidur RahmanMajidur Rahman
Basic Search AlgorithmsBasic Search Algorithms
How do we find the solutions of previous
problems?
• Search the state space
– State space can be represented by a search tree
– Root of the tree is the initial state
– Children generated through successor function
• In general we may have a search graph rather
than tree (same state can be reached through
multiple paths)
16
Majidur RahmanMajidur Rahman
Simple Tree Search ExampleSimple Tree Search Example
17
Majidur RahmanMajidur Rahman
Simple Tree Search ExampleSimple Tree Search Example
18
Majidur RahmanMajidur Rahman
Simple Tree Search ExampleSimple Tree Search Example
19
Majidur RahmanMajidur Rahman
State Space vs. Search TreeState Space vs. Search Tree
• A state corresponds
to a configuration of
the world
• A node is a data
structure in a search
tree
– e.g. node = <state,
parent-node, action,
path-cost, depth>
20
Majidur RahmanMajidur Rahman
Search StrategiesSearch Strategies
 A search strategy is defined by picking the order of node
expansion
 Problem-solving performance is measured in four ways:
• Completeness: Is a solution found if one exists?
• Optimality: Does the strategy find the optimal solution?
• Time Complexity: How long does it take to find a solution?
• Space Complexity: How much memory is needed to perform
the search?
 Time and space complexity are measured in terms of
problem difficulty defined by:
• b - branching factor of the search tree
• d - depth of the shallowest goal node
• m - maximum length of any path in the state space
21
Majidur RahmanMajidur Rahman
Uninformed Search StrategiesUninformed Search Strategies
• Uninformed search (or blind search)
– Strategies have no additional information about states beyond
that provided in the problem definition
• Informed (or heuristic) search
– Search strategies know whether one state is more promising
than another
• Uninformed strategies (defined by order in which nodes
are expanded):
– Breadth-first search
– Uniform-cost search
– Depth-first search
– Depth-limited search
– Iterative deepening search
– Bidirectional search
22
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
• Expand shallowest unexpanded node
• Fringe is the collection of nodes that have been generated
but not yet expanded.
• The set of all leaf nodes available for expansion at any
given point is called the frontier.
• Implementation: fringe/frontier is a FIFO queue
23
Breadth-First SearchBreadth-First Search
24
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
25
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
26
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
• Completeness: is a solution always found
if one exists?
– YES
• If shallowest goal node is at some finite depth d
• If branching factor b is finite
• BF search is optimal if the path cost is a
non-decreasing function of the depth of
the node
27
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
• Time complexity: Assume a state space where
every state has b successors
– Assume solution is at depth d
– Worst case: expand all but the last node at depth d
– Total number of nodes generated:
– b + b2
+ b3
+ ...+ bd
+ (bd +1
− b) = O(bd +1
)
• Space complexity: every node generated must
remain in memory, so same as time complexity
28
Majidur RahmanMajidur Rahman
Breadth-First SearchBreadth-First Search
• Memory requirements are a bigger problem than
execution time.
29
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
• Extension of BF-search:
– Expand node with lowest path cost
• Implementation: fringe = queue ordered by
path cost
• UC-search is the same as BF-search
when all step costs are equal
30
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
 Let us consider the following search tree, where A
and G are the initial and goal node, respectively.
31
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
32
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
33
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
34
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
35
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
36
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
 Let us consider the another search tree, where A
and G are the initial and goal node, respectively.
37
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
38
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
39
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
40
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
41
Majidur RahmanMajidur Rahman
Uniform-Cost SearchUniform-Cost Search
• Completeness:
– YES, if step-cost > some small positive constant ε
• Optimality:
– nodes expanded in order of increasing path cost
– YES, if complete
• Time and space complexity:
– Uniform-cost search is guided by path costs rather than
depths, so its complexity cannot easily be characterized
in terms of b and d.
– Instead, assume C* is the cost of the optimal solution
– Assume that every action costs at least ε
– Worst-case: O(bC*/ε
)
42
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
43
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
44
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
45
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
46
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
47
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
48
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
49
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
50
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
51
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
52
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
53
Majidur RahmanMajidur Rahman
Depth-First SearchDepth-First Search
• Expand deepest unexpanded node
• Implementation: fringe is a LIFO queue (= stack)
54
Majidur RahmanMajidur Rahman
DF-Search: EvaluationDF-Search: Evaluation
• Completeness:
– Is a solution always found if one exists?
– No (unless search space is finite and no loops
are possible)
• Optimality:
– Is the least-cost solution always found?
– No
55
Majidur RahmanMajidur Rahman
DF-Search: EvaluationDF-Search: Evaluation
• Time complexity: O(bm
)
• In general, time is terrible if m (maximal
depth) is much larger than d (depth of
shallowest solution)
– But if there exist many solutions then faster
than BF-search
• Space complexity: O(bm)
– Backtracking search uses even less memory
(one successor instead of all b)
56
Majidur RahmanMajidur Rahman
Depth-Limited SearchDepth-Limited Search
• DF-search with depth limit l
– i.e. nodes at depth l have no successors
– Problem knowledge can be used
• Solves the infinite-path problem
• If l < d then incompleteness results
• Time complexity: O(bl
)
• Space complexity: O(bl)
57
Majidur RahmanMajidur Rahman
Depth-Limited Search withDepth-Limited Search with ll = 2= 2
58
Majidur RahmanMajidur Rahman
Depth-Limited Search withDepth-Limited Search with ll = 2= 2
59
Majidur RahmanMajidur Rahman
Depth-Limited Search withDepth-Limited Search with ll = 2= 2
60
Majidur RahmanMajidur Rahman
Depth-Limited Search withDepth-Limited Search with ll = 2= 2
61
Majidur RahmanMajidur Rahman
Iterative Deepening SearchIterative Deepening Search
• A general strategy to find best depth limit l
– Goal is found at depth d, the depth of the
shallowest goal-node
– Often used in combination with DF-search
• Combines benefits of DF- and BF-search
62
Majidur RahmanMajidur Rahman
ID-Search: ExampleID-Search: Example
63
Majidur RahmanMajidur Rahman
ID-Search: ExampleID-Search: Example
64
Majidur RahmanMajidur Rahman
ID-Search: ExampleID-Search: Example
65Majidur RahmanMajidur Rahman
ID-Search: ExampleID-Search: Example
66Majidur RahmanMajidur Rahman
Bidirectional SearchBidirectional Search
Two simultaneous searches run from start and goal.
– Motivation:
– One forward from the initial state
– Other backward from goal
– Stops when the two searches meet in the middle
• Check whether the node belongs to the other fringe before
expansion
67
bd/2
+bd/2
≠bd
Bidirectional SearchBidirectional Search
Time complexity: O(bd/2
)
Space complexity: O(bd/2
)
– This space complexity is the most significant
weakness of bidirectional search.
Completeness and Optimality: Yes
– If step costs are uniform
– If both searches are breadth-first search.
68Majidur RahmanMajidur Rahman
The reduction in time complexity makes
bidirectional search attractive, but how do we
search backwards?
The predecessor of each node should be
efficiently computable.
– When actions are easily reversible.
Bidirectional SearchBidirectional Search
Majidur RahmanMajidur Rahman
Summary of AlgorithmsSummary of Algorithms
70
Majidur RahmanMajidur Rahman
********** ********** If You Need Me ********** **********
Mail: tajim.cse@diu.edu.bd
Website: https://www.tajimiitju.blogspot.com
ORCID: https://orcid.org/0000-0002-2834-1507
LinkedIn: https://www.linkedin.com/in/tajimiitju
ResearchGate: https://www.researchgate.net/profile/Tajim_Md_Niamat_Ullah_Akhund
YouTube: https://www.youtube.com/tajimiitju?sub_confirmation=1
SlideShare: https://www.slideshare.net/TajimMdNiamatUllahAk
Facebook: https://www.facebook.com/tajim.mohammad
GitHub: https://github.com/tajimiitju
Google+: https://plus.google.com/+tajimiitju
Gmail: tajim.mohammad.3@gmail.com
Twitter: https://twitter.com/Tajim53
Thank you
Tajim Md. Niamat Ullah AkhundTajim Md. Niamat Ullah Akhund