Professional Documents
Culture Documents
MODULE 1
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
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,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
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
• 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:
• 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
• 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
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
• 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
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,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