1. CHAPTER - 2
Problem Spaces and
P roblem Solving by
Presented By :
Radhika Srinivasan PG
Roll No : 45
2. What we will learn today …
What is Problem Spaces?
How to Search to get solutions?
Using Different searching algorithms i.e.
basically used in AI
Some Toy problems and Real world problems
Now, we’ll study about what are the kinds of problems
where the AI is concerned and the technique that is
used to solve those problems.
There are 4 things concerned to solve a particular
Define the problem precisely.
Analyze the problem.
Isolate and represent the task knowledge i.e. required
to solve the problem.
Finally, choose the best problem solving technique and
apply to the particular problem.
-Play games, e.g chess
-Symbolic integration of mathematical formulas.
-Some programs can improve their performance with
– Prove assertions (theorems) by manipulating a database
– Understanding of natural language
– E.g. Spelling checker
– Write computer programs based on a description
Systems and languages
– Time-sharing, list processing, and interactive debugging
were developed in the AI research
6. What is problem space ?
Problem space is a set of states and the connections
between to represent the problem. Problem space graph
is used to represent a problem space. In the graph, the
states are represented by nodes of the graph, and the
operators by edges between nodes.
For simplicity they are often represented as trees,
where the initial state is the root of the tree. The cost of
the simplification is that any state that can be reached
by two different paths will be represented by duplicate
nodes thereby increasing the tree size. The benefit of
using tree is that the absence of cycles greatly
simplifies many search algorithms.
State Space and Problem Reduction
– State space
An operator produces exactly one new state
– Problem reduction
An operator produces a set of sub problems, each of
which have to be solved.
Tower of Hanoi
8. Search - problem representation
State space graph
It is represented like nodes and edges where initial
state to the goal state. It can also represent as tree
9. Search Strategy
A strategy is defined by picking the order of node
expansion. Strategy is evaluated among the following
Completeness- does it always find a solution if one
Time complexity- no. of nodes generated.
Space complexity- max no. of nodes in memory.
Optimality- does it always find least cost solution?
Time and space is measured in ‘b’ – max branching
factor of search tree. ‘d’- depth of least cost solution.
‘m’ – max depth of the state space may be (infinite)
10. Which are the Search Types ?
Blind search algorithms are as follows:
In blind search the number of nodes can be
extremely large, The order of expanding the nodes is
- Breadth First Search
- Depth First Search
- Ordered Search
- A* An optimal search
Consider State space graph as general graph i.e. nodes
and points. Graphs can be directed undirected or mixed
11. Breadth-First Search
Breadth First Search (BFS) searches breadth-wise in
the problem space. Breadth-First search is like
traversing a tree where each node is a state which may
a be a potential candidate for solution.
Breadth first search expands nodes from the root of the
tree and then generates one level of the tree at a time
until a solution is found. It is very easily implemented
by maintaining a queue of nodes.
Initially the queue contains just the root. In each
iteration, node at the head of the queue is removed and
then expanded. The generated child nodes are then
added to the tail of the queue.
12. ALGORITHM: BREADTH-FIRST SEARCH
Create a variable called NODE-LIST and set it to the
Loop until the goal state is found or NODE-LIST is
• Remove the first element, say E, from the NODE-
LIST. If NODE-LIST was empty then quit.
• For each way that each rule can match the state
described in E do:
- Apply the rule to generate a new state.
- If the new state is the goal state, quit and return this
- Otherwise add this state to the end of NODE-LIST
13. Advantages : BFS
Breadth first search will never get trapped exploring the
useless path forever.
If there is a solution, BFS will definitely find it out.
If there is more than one solution then BFS can find the
minimal one that requires less number of steps.
14. Disadvantages :BFS
The main drawback of Breadth first search is its
memory requirement. Since each level of the tree must
be saved in order to generate the next level, and the
amount of memory is proportional to the number of
nodes stored, the space complexity of BFS is O(bd).
As a result, BFS is severely space-bound in practice so
will exhaust the memory available on typical computers
in a matter of minutes.
If the solution is farther away from the root, breath first
search will consume lot of time.
15. DEPTH FIRST SEARCH
Depth First Search (DFS) searches deeper into the
BFS always generates successor of the deepest
Depth First Search uses last-in first-out stack for
keeping the unexpanded nodes.
More commonly, depth-first search is implemented
recursively, with the recursion stack taking the place of
an explicit node stack.
16. ALGORITHM: DEPTH FIRST SEARCH
If the initial state is a goal state, quit and return
Otherwise, loop until success or failure is signalled.
a) Generate a state, say E, and let it be the successor
of the initial state. If there is no successor, signal
b) Call Depth-First Search with E as the initial state.
c) If success is returned, signal success. Otherwise
continue in this loop.
The advantage of depth-first Search is that memory
requirement is only linear with respect to the search
The time complexity of a depth-first Search to depth d
is O(b^d) since it generates the same set of nodes
If depth-first search finds solution without exploring
much in a path then the time and space it takes will be
There is a possibility that it may go down the left-most
path forever. Even a finite graph can generate an
Depth-First Search is not guaranteed to find the
And there is no guarantee to find a minimal solution, if
more than one solution exists.
19. Bidirectional Search
The algorithms so far use forward reasoning, i.e.
moving from the start node towards a goal node. some
cases we could use backward reasoning, i.e. moving
from the goal state to the start state.
Forward and backward reasoning can be combined into
a technique called bidirectional search.
- One starting from the initial state and searching
- One starting from the goal state and searching
backward The search terminates when the two graphs
20. Problems in Real World
There are some toy searching that we’ll see
this technique are used to solve some real world
Route finding.(computer networks, airline travel
Layout problems (VLSI layout, furniture layout,
Assembly sequencing.(Assembly of electrical motors)
Task Scheduling.(Time tables, manufacturing)
21. Water Jug Problem
Consider the following problem:
A Water Jug Problem: You are given two jugs, a
4-gallon one and a 3-gallon one, a pump which has
unlimited water which you can use to fill the jug, and
the ground on which water may be poured. Neither jug
has any measuring markings on it. How can you get
exactly 2 gallons of water in the 4-gallon jug?
State Representation and Initial State –
We will represent a state of the problem as a tuple
(x, y) where x represents the amount of water in the 4-
gallon jug and y represents the amount of water in the
3-gallon jug. Goal state as (2,y).
26. 8 Puzzle Problem
State space (S)
Location of each of the 8 tiles(and the blank tile)
Start State (s)
Four Operators : Right, Left, Up, Down
one of the goal configuration
27. 8 Queen Problem
Problem: Place 8 queens on a chess board so that none
of them attack each other
- A state is an arrangement of 0 to 8 queens on the
- Operators add a queen to any square.
This formulation is not a systematic way to find the
solution, it takes a long time to get the solution.
28. 8 Queen Problem
Formulation – II
- A state is an arrangement of 0-8 queen with no one
- Operators place a queen in the left most empty
- More systematic than formulation-I
29. 8 Queen Problem
- A state is an arrangement of 8 queens on in each
-Operators move an attacked queen to another square
in the same column.
-Keep on shuffling the queen until the goal is reached.
- This formulation is more systematic hence , it is also
called as Iterative Formulation.
31. Missionaries and Cannibals
Three missionaries and three cannibals find themselves
on a side of river. They agreed to get to the other side
of river. But missionaries are afraid of being eaten by
cannibals so, the missionaries want to manage the trip
in such a way that no. of missionaries on either side of
the river is never less than the no. of cannibals on the
same side. The boat is able to hold only 2 people at a
32. Missionaries and Cannibals
#m – number of missionaries on first bank
#c – number of cannibals on first bank
The last bit indicate whether the boat is in the first
• Boat carries (1,0) or (0,1) or (1,1) or (2,0) or (0,2)