Module - Ii: 20mca188 Artificial INTELLIGENCE (Elective-2)
Module - Ii: 20mca188 Artificial INTELLIGENCE (Elective-2)
Module - Ii: 20mca188 Artificial INTELLIGENCE (Elective-2)
20MCA188 ARTIFICIAL
INTELLIGENCE (Elective-2) Selma Joseph A.
Search algorithms are one of the most important areas
of artificial intelligence.
Combinatorial optimization, decision analysis, game
playing, learning, planning, pattern recognition,
robotics and theorem proving are some of the areas in
which search algorithms play a key role.
Graphs
A graph G is an ordered pair (V , E) where the
elements of V are called vertices or nodes and the
elements of E are called edges or sides. Each element of
E can be thought of an arc joining two vertices in V.
❑ If the arcs may have specific directions in which case
the graph is called a directed graph.
❑ If there are more than one edge joining two vertices,
the graph is called a multigraph.
There may also be loops in graphs, a loop being an
edge joining a vertex with itself.
Trees
A graph is said to be connected if there is a path along the edges joining any
two vertices in the graph. A path which returns to the starting vertex is called
a cycle. A tree is a connected graph without cycles.
A rooted tree
Search algorithm
• The process of looking for a sequence of actions that reaches
the goal is called search.
• A search algorithm takes a problem as input and returns a
solution in the form of an action sequence.
• Once a solution is found, the actions it recommends can be
carried out. This is called the execution phase.
Search tree
• Having formulated some problems, we need to solve them.
The possible action sequences starting at the initial state form
a search tree with the initial state at the root; the branches are
actions and the nodes correspond to states in the state space of
the problem.
• The root node of the tree corresponds to the initial state.
Search tree
Example
Consider a person intending to travel from Arad to
Bucharest in Romania.
• Strategies that know whether one non-goal state is “more promising” than
another are called informed search or heuristic search strategies.
Let us assume that we are currently at Arad and we want to get to
Bucharest. To construct a search tree we start by designating the
initial state as the root node. In the present problem, the initial state is
the city of Arad and so we designate Arad as the root node. There are
three possible actions that we can take while we are at Arad, namely,
go to Sibiu, go to Timisoara and go to Zerind. These actions define
three branches of the search tree emanating from the root node and
ending at the nodes named as Sibiu, Timisoara and Zerind. These
three branches form level 1 of the search tree. A blind search will
have no preference as to which node it should explore first.
Suppose we arbitrarily move to Sibiu. Then the possible actions are:
go to Arad, go to Rimnicu Vicea, go to Fagaras and go to Oradea.
These actions produce four branches from the node.
Remarks
The search tree shown in (c) includes the path from Arad to Sibiu and back
to Arad again! We say that Arad is a repeated state in the search tree,
generated in this case by a loopy path.
Breadth-first search is a simple strategy in which
the root node is expanded first, then all the
successors of the root node are expanded next, then
their successors, and so on. In general, all the nodes
are expanded at a given depth in the search tree
before any nodes at the next level are expanded.
Algorithm
The algorithm returns the goal state or failure.
1. Create a variable called NODE-LIST and set it to the initial state.
2. Until a goal state is found or NODE-LIST is empty do:
(a) Remove the first element from NODE-LIST and call it E. If NODE-
LIST was empty, quit and return failure.
(b) For each way that each rule can match the state described in E do:
i. Apply the rule to generate a new state.
ii. If the new state is a goal state, quit and return this state.
iii. Otherwise, add the new state to the end of NODE-LIST.
0 1 2 3 4 5 6
Examples
Example 1
Let the search tree be as in Figure the initial and goal states being 1 and 8
respectively. Apply the breadth-first search algorithm to find the goal state.
Examples
Example 2
Consider the water jug problem and the associated production rules. We now
construct the search tree using the breadth-first search algorithm.
Stage 1. Construct a tree with the initial state (0, 0) as its root.
Fig 1: (0,0)
Stage 2. Construct all the children of the root by applying each of the
applicable rules to the initial state. Then we get a tree. Fig 2:
Stage 3. Now for each leaf node in Figure 3.9, generate all its successors by
applying all the rules that are appropriate. The tree at this point is
Fig 3:
Stage 4. The process is
continued until we get a
node representing the goal
state, namely, (2, 0).
Algorithm
Let the search tree be as in Figure, the initial and goal states being 1 and 7
respectively. Apply the depth-first search algorithm to find the goal state.
Fig 1: (0,0)
Stage 2. We generate a successor E for (0, 0). We choose the successor obtained
by the application of Rule 1 in the production rules. Then we get a tree as in
Fig 2. Fig 2:
Stage 3. Now for the leaf node in Figure 2, generate a successor by applying
an applicable rule. The tree at this point is Fig 3.
Fig 3:
Stage 4. The process is
continued until we get a
node representing the goal
state, namely, (2, 0).
Iterative deepening combines the benefits of depth-first and breadth-first
searches. Like breadth-first search, the iterative deepening search is guaranteed
to find a solution if one exists. In general, iterative deepening is the preferred
uninformed search method when the search space is large and the depth of the
solution is not known.
Algorithm
1. Set SEARCH-DEPTH = 1.
2. Conduct a depth-first search to a depth of SEARCH-DEPTH. If a solution is
found, then return it.
3. Otherwise, increment SEARCH-DEPTH by 1 and go to step 2.
Iterative deepening
The order in which the nodes are explored in iterative deepening
Advantages and disadvantages
1. The DFID will always find the shortest solution path to the goal state if it
exists.
2. The maximum amount of memory used is proportional to the number of
nodes in the solution path.
3. All iterations but the final one are wasted.
4. The DFID is slower than the depth-first search only by a constant factor.
5. DFID is the optimal algorithm in terms of space and time for uninformed
search.