You are on page 1of 53

Amity School of Engineering and Technology

MODULE 1

Scope of AI & Problem Solving

B.Tech.(IT), VI
Artificial Intelligence
A revisit what learned till now
• All these problems have got a common structure:
– an initial situation
– achieve a certain goal.
– At any point in time different simple actions/operators
available(e.g. “turn left” vs. “turn right”).
– Applying these operators the state changes
– Executing a particular sequence of such actions may or may
not achieve the goal.

2
A revisit what learned till now
– Search is the process of inspecting several such sequences
and choosing one that achieves the goal.
– For some applications, each sequence of actions may be
associated with a certain cost.
– A search problem where we aim not only at reaching our goal
but also at doing so at minimal cost is an optimisation problem.

3
Amity School of Engineering and Technology

Production System
Since search forms the core of many intelligent processes, it is useful to
structure AI programs in a way that facilitates describing and
performing the search process. Production systems provide such
structures.
A production system consist of:-
• A set of rules, each consisting of a left side (pattern) that determines
the applicability of the rule and a right side describing the operation
to be performed.
• One or more knowledge/databases that contain whatever information
is appropriate for the particular task.
• A control strategy that specifies the order in which the rules will be
compared to the database and a way of resolving the conflicts that
arise when several rules match at once.
• A rule applier which is the computational system that implements
the control strategy and applies the rules.
Amity School of Engineering and Technology

Classes of Production System


•Monotonic production system: the application of a rule
never prevents the later application of another rule that
could also have been applied at the time the first rule was
selected.
•Non-monotonic production system: Is one in which this
is not true.
•Partially commutative production system: the
application of a particular sequence of rules transforms state
x into state y, then any permutation of those rules that is
allowable also transforms state x into state y.
•Commutative production system: system that is both
monotonic and partially commutative.
Amity School of Engineering and Technology

Control strategies
•A control strategy that specifies the order in which the rules
will be applied.
•Control strategies help us to overcome the abnormal
situations, when there are more than one rules or fewer than
one rule will have its left sides match the current state.
•Requirement for control strategy
i.A good control strategy causes motion
ii.A good control strategy is systematic
Search
• Search is the fundamental technique of AI.
– Possible answers, decisions or courses of action are structured
into an abstract space, which we then search.
• Search is either "blind" or “uninformed":
– blind
• we move through the space without worrying
about what is coming next, but recognising the
answer if we see it
– informed
• we guess what is ahead, and use that information
to decide where to look next.
• We may want to search for the first answer that satisfies our goal,
or we may want to keep searching until we find the best answer .
Example: Water Pouring
(0,0)

(4,0) (0,3)

(1,3) (4,3) (3,0)

(1,0) (0,1)
(3,3) (4,2)

(4,1)
(2,3)

(2,0) (0,2)

0 8
3
/
Amity School of Engineering and Technology
• The set of all possible sequences of legal moves form a
tree:
– The nodes of the tree are labelled with states (the same state
could label many different nodes).
– The initial state is the root of the tree.
– For each of the legal follow-up moves of a given state, any
node labelled with that state will have a child labelled with the
follow-up state.
– Each branch corresponds to a sequence of states (and thereby
also a sequence of moves).
10
Amity School of Engineering and Technology

Search Strategies

1.Uninformed search (blind search)(Exhaustive search)


(Bruteforce)
Having no information about the number of steps from
the current state to the goal.

2.Informed search (heuristic search)


More efficient than uninformed search.
Amity School of Engineering and Technology

Brute Force or Uninformed Search Strategies


• These are commonly used search procedure which
explore all the alternatives during the search process.
• They do not have any domain specific knowledge.
• They need the initial state, the goal state and a set of legal
operators.
• The strategy gives the order in which the search space is
searched
• The followings are example of uninformed search
–Depth First Search (DFS)
–Breadth First Search (BFS)
Amity School of Engineering and Technology

Depth First Search

• The search begins by expanding the initial node,


generate all successors of the initial node and test
them.
• Depth-first search always expands the deepest node
in the current frontier of the search tree.
• Depth-first search uses a LIFO approach.
Depth First Search
Depth First Search
• Step 0
Let's start with our root/goal node:
• We can use two lists to keep track of what we are doing -
an Open list and a Closed List. An Open list keeps track
of what you need to do, and the Closed List keeps track
of what you have already done. Right now, we only have
our starting point, node A. We haven't done anything to it
yet, so let's add it to our Open list.
Depth First Search
• Open List: A
• Closed List: <empty>
• Step 1
Now, let's explore the neighbors of our A node. To put
another way, let's take the first item from our Open list
and explore its neighbors:
Depth First Search

• Node A's neighbors are the B and C


nodes. Because we are now done with our
A node, we can remove it from our Open
list and add it to our Closed List. You aren't
done with this step though. You now have
two new nodes B and C that need
exploring. Add those two nodes to our
Open list
Depth First Search
• Our current Open and Closed Lists contain the following
data:
– Open List: B, C
– Closed List: A
• Step 2
Our Open list contains two items. For depth first search and
breadth first search, you always explore the first item from our
Open list. The first item in our Open list is the B node. B is not our
destination, so let's explore its neighbors:
Depth First Search

• Because we have now expanded B, we


are going to remove it from the Open list
and add it to the Closed List. Our new
nodes are D and E, and we add these
nodes to the beginning of our Open list:
– Open List: D, E, C
– Closed List: A, B
Depth First Search
• Because D is at the beginning of our Open List, we
expand it. D isn't our destination, and it does not contain
any neighbors. All you do in this step is remove D from
our Open List and add it to our Closed List:
– Open List: E, C
– Closed List: A, B, D
Depth First Search
• Step 4
We now expand the E node from our Open list. E is not
our destination, so we explore its neighbors and find out
that it contains the neighbors F and G. Remember, F is
our target, but we don't stop here though. Despite F being
on our path, we only end when we are about to expand
our target Node - F in this case
Depth First Search

• Our Open list will have the E node


removed and the F and G nodes added.
The removed E node will be added to our
Closed List:
– Open List: F, G, C
– Closed List: A, B, D, E
Depth First Search
• Step 5
We now expand the F node. Since it is our intended
destination, we stop:
Depth First Search
• We remove F from our Open list and add it to our Closed
List. Since we are at our destination, there is no need to
expand F in order to find its neighbors.
• Our final Open and Closed Lists contain the following
data:
– Open List: G, C
– Closed List: A, B, D, E, F
Depth First Search

• The final path taken by our depth first


search method is what the final value of
our Closed List is: A, B, D, E, F.
Amity School of Engineering and Technology

Advantages of Depth-First Search


• It requires less memory since only the nodes of the current
path are stored.
• By chance, it may find a solution without examining
much of the search space at all.
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8

1 7

2 3
8

4 5

6
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8
1

1 7 1 L0

L1
2 3
8

4 5 L2

6 L3
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8
1 2 3

1 7 1 L0

3 L1
2 3 2

4 5 L2

6 L3
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8
1 2 3 4 5

1 7 1 L0

3 L1
2 3 2

8
4 5
4 5 L2

6 L3
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8
1 2 3 4 5 6

1 7 1 L0

3 L1
2 3 2

8
4 5
4 5 L2
9

6 L3
DFS Data Structures
queue<Node> 1 2 3 4 5 7 8 6

vector<bool> 1 2 3 4 5 6 7 8

1 7 1 L0

2 3 L1
2 3
8

4 5 4 5 7 8 L2

6 6 L3
33
Breadth First Search

• Depth and breadth first search methods


are both similar. In depth first search,
newly explored nodes were added to the
beginning of your Open list. In breadth
first search, newly explored nodes are
added to the end of your Open list.
Breadth First Search
• Let's see how that change will affect our
results. Consider the search tree below

• Find a path between nodes A and E.


Breadth First Search

• Step 0
Let's start with our root/goal node:
• We will continue to employ the Open and
Closed Lists to keep track of what needs
to be done:
– Open List: A
– Closed List: <empty>
Breadth First Search
• Step 1
Let's explore the neighbors of our A node. So far,
we are following in depth first's footsteps:

• Remove A from Open list and add A to Closed


List. A's neighbors, the B and C nodes, are added
to our Open list. They are added to the end of
our Open list, but since our Open list was empty
(after removing A), it's hard to show that in this
step.
Breadth First Search
• Current Open and Closed Lists contain the following data:
– Open List: B, C
– Closed List: A
• Step 2
Things start to diverge from depth first search method in
this step. We take a look the B node because it appears
first in our Open List.
Breadth First Search
• Because B isn't intended destination, we
explore its neighbors:

• B is now moved to Closed List, but the neighbors


of B, nodes D and E are added to the end of
Open list:
– Open List: C, D, E
– Closed List: A, B
Breadth First Search
• Step 3
We expand C node:

Since C has no neighbors, all we do is remove C


from our Closed List and move on:
– Open List: D, E
– Closed List: A, B, C
Breadth First Search
• Step 4
Similar to Step 3, we expand node D. Since it isn't the
destination, and it too does not have any neighbors, we
simply remove D from Open list, add D to Closed List,
and continue on:
– Open List: E
– Closed List: A, B, C, D
Breadth First Search

• Step 5
Because our Open list only has one item,
we have no choice but to look at node E.
Since node E is the destination, we can
stop here:
Breadth First Search

• Our final versions of the Open and Closed


Lists contain the following data:
– Open List: <empty>
– Closed List: A, B, C, D, E
Amity School of Engineering and Technology

Search Strategies: Blind Search

• Breadth-first search
Expand all the nodes of
one level first.

• Depth-first search
Expand one of the nodes at
the deepest level.
Amity School of Engineering and Technology

Disadvantages of Depth-First Search

• Determination of the depth until which the search has to


proceed. This depth is called cut-off depth.
• If the cut-off depth is smaller, solution may not be found.
• If cut-off depth is large, time complexity will be more.
• And there is no guarantee to find a minimal solution, if
more than one solution exists.
Amity School of Engineering and Technology

Breadth First Search

• Searching processes level by level unlike depth first


search which goes deep into the tree.
• An operator is employed to generate all possible
children of a node.
Amity School of Engineering and Technology

Time and space complexity

Time Complexity :
1 + b + b2 + b3 +…+……bd.
Hence Time complexity = O (bd)

Space Complexity :
1 + b + b2 + b3 +…+……bd.
Hence Space complexity = O (bd)
Amity School of Engineering and Technology

Advantages of Breadth-First Search

• 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.
Amity School of Engineering and Technology

Disadvantages of Breadth-First Search

• It requires more memory


• Searching process remembers all unwanted nodes which
is of no practical use for the search.
Amity School of Engineering and Technology

DFS Vs BFS
DFS BFS
It require less memory because only the It require more memory because all the tree
nodes on the current path are stored. that has so far been generated must be
stored.
It is one in which by luck solution can be While in BFS all parts of the tree must be
found without examining much of the examined to level n before any nodes on
search space at all. level n+1 can be examined.
It does not give optimal solution. It gives optimal solution.
DFS may find a long path to a solution in BFS guarantees to find a solution if it
one part of the tree, when a shorter path exists. Furthermore if there are multiple
exists in some other, unexplored part of the solutions, then a minimal solution will be
tree. found.
Time complexity: O(bd ) Time complexity: O(bd )
where b : branching factor, d: depth where b : branching factor, d: depth
Space complexity: O(d) , d: depth Space complexity: O(bd )
where b : branching factor, d: depth
Write the path using DFS and BFS for given graph

(0,0)

(4,0) (0,3)

(1,3) (4,3) (3,0)

(1,0) (0,1)
(3,3) (4,2)

(4,1)
(2,3)

(2,0) (0,2)

0 51
3
/
52
Amity School of Engineering and Technology

Thank You

You might also like