Chapter 2 Problems and Searching

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Chapter-2

Search and constraint specifications

Que-1: Explain Intelligent system? What is an agent? List types of agent.

Intelligent system:
Intelligent system is a system that shows a type of knowledge.

Agent:
An agent is something that sees (perceives) and acts accordingly.

Agent interacts with environment through sensors and actuators.

Types of Agents:
1. Human Agent
2. Robotics agent
3. Software agent

Que-2: What is problem? What is problem solving? Explain general algorithm of problem
solving.

Problem:
Problem is a question to be solved.

Problem Solving:
Problem solving is the analysis of how computer is used to find solutions in specific domains.

Problem solving is defined as the way where an agent finds a sequence of actions to achieve
the goal. A good example of problem is “ Tower of Hanoi”.

General algorithm for problem solving


Any one algorithm for a particular problem is not applicable for all types of problems in
varieties of situations. So there will be general problem solving algorithm.
Step 1: Analyse the problem.
Step 2: Find the starting state and goal state.
Step 3: Find out the data for starting state and goal state.
Step 4: Find out rules to reach to goal state from starting state.
Step 5: Select some rules from set of rules and apply on data.
Step 6: Apply those rules on initial state and proceed.
Step 7: Determine the new states generated after applying these rules and marked them as
current state.
Step 8: Achieve some information from goal state and apply on current state to achieve goal
state.
Step 9: Get the goal state
Step 10: Exit.

Que-3: What is the Tower of Hanoi? How to solve Tower of Hanoi puzzle? Explain it with 3
disk example.
 The Tower of Hanoi is a mathematical puzzle comprising three rods and numerous
disks placed one over the other.
 It is also known as the Tower of Brahma or the Lucas tower, as the French
mathematician Edouard Lucas introduced it back in 1883.
 This puzzle has three rods and a variable number of stacked disks. Those rods are
designed as cyclic towers. So, the larger disks in diameter are stacked on the bottom,
and the smaller disks are stacked on top.
 Initially, we are given three pegs or rods. And one of them (A, shown in the example)
has all the disks stacked. We aim to move an entire stack of disks from one rod (A) to
another (C) by obeying some specific rules.
 Here is the initial setup of the puzzle-

 And this is the final goal-


Rules of Tower of Hanoi

 The initial state of this puzzle, all the disks will be stacked in rod one.
 The final state is all those disks from rod one will be stacked upon rod two or rod
three.
 We can move an on-disk from one rod to another at any given time.
 We can only move the uppermost disk from the rod.
 A disk can’t be placed over another disk, which is smaller.

We will have a Tower of Hanoi setting of n disks would cost (2n – 1) move.

How to solve Tower of Hanoi Puzzle


Let’s illustrate the algorithm for three disks and consider peg A as the source, peg B as the
helper, and peg C as the destination

Step 1) Initially, all the disks will be stacked on peg A.

At this stage: Source = Peg A


Destination = Peg C
Helper = Peg B , Now, we need to move the top n-1 disks from the source to the helper.

Note: Though we can only move one disk at a time, it breaks our problem from a 3-disk
problem to a 2-disk problem, which is a recursive call.

Step 2) As we call a recursive call from peg A and the destination is peg B, we will use peg C
as a helper.

Now we need to move n-1 or one disk from source to helper, moving the smallest disk from
peg A to peg C.
At this stage: Source = peg A
Destination = peg B
Helper = peg C

Step 3) Then, according to our algorithm, the nth or 2nd disk needs should be transferred
into the destination or peg B.

At this stage: Source = peg A


Destination = peg B
Helper = peg C

Step 4) Now, we will move the n-1 disks or disk one from helper or peg C to the destination
or peg B according to the third stage of our algorithm.

At this stage: Source = peg A


Destination = peg B
Helper = peg C

Step 5) After completing the recursive call, we will return to our previous setting when the
first stage of the algorithm.

Step 6) Now, in the second stage, we will move our source to our destination, which is moving
disk 3 to peg C from peg A.

At this stage: Source = peg A


Destination = peg C
Helper = peg B
Step 7) Now we can see that

task is to move the remaining disks from helper (peg B) to destination (peg C). We will use the
initial source or peg A as a helper in this case.

Step 8) As we can’t move two disks simultaneously, we will call a recursive call for disk 1.
According to the last step and our algorithm, a destination in this step is peg A.

At this stage: Source = peg B


Destination = peg A
Helper = peg C

Step 9) Our recursive call is completed now. Then we move disk 2 from its source to its
destination.

At this stage: Source = peg B


Destination = peg C
Helper = peg A

Step 10) Then we move our remaining n-1 or disk 1 from helper to destination.
At this stage:Source = peg A
Destination = peg C
Helper = peg B

Que-4: Explain Water Jug Problem in Artificial Intelligence using tree diagram.
Water Jug Problem:

 There are two jugs of volume A litre and B litre. Neither has any measuring mark on
it. There is a pump that can be used to fill the jugs with water. How can you get
exactly x litre of water into the A litre jug. Assuming that we have unlimited supply of
water.
 Note: Let's assume we have A=4 litre and B= 3 litre jugs. And we want exactly 2 Litre
water into 4 litre jug A.

Solution:

Start State: (0,0) and Goal State: (2,0)

Generate production rules for the water jug problem

We basically perform three operations to achieve the goal.

1. Fill water jug.


2. Empty water jug
3. Transfer water jug

Initialization:

Start State: (0,0)

1. Fill 3-gallon jug, Now the state is (0,3)


2. Pour all water from 3-gallon jug into 4-gallon jug, Now the state is (3,0)
3. Fill 3-gallon jug, Now the state is (3,3)
4. Pour water from 3-gallon jug into 4-gallon jug until 4-gallon jug is full, Now the state
is (4,2)
5. Empty 4-gallon jug, Now state is (0,2),
6. Pour 2 gallon water from 3 gallon jug into 4 gallon jug.
7. Now the state is (2,0)-- Goal Achieved.
Tree diagram Representation of water Jug Problem:

(4,0) (0,3)

Que-5: Explain various possible states in water jug problem with two jugs having capacity 4
litre and 3 litre.

Rule State Process

(4,Y)
1 (X,Y | X<4)
{Fill 4-gallon jug}

(X,3)
2 (X,Y |Y<3)
{Fill 3-gallon jug}

(0,Y)
3 (X,Y |X>0)
{Empty 4-gallon jug}

(X,0)
4 (X,Y | Y>0)
{Empty 3-gallon jug}
Rule State Process

(4,Y-(4-X))
5 (X,Y | X+Y>=4 ^ Y>0)
{Pour water from 3-gallon jug into 4-gallon jug until 4-gallon jug is full}

(X-(3-Y),3)
6 (X,Y | X+Y>=3 ^X>0)
{Pour water from 4-gallon jug into 3-gallon jug until 3-gallon jug is full}

(X+Y,0)
7 (X,Y | X+Y<=4 ^Y>0)
{Pour all water from 3-gallon jug into 4-gallon jug}

(0,X+Y)
8 (X,Y | X+Y <=3^ X>0)
{Pour all water from 4-gallon jug into 3-gallon jug}

(2,0)
9 (0,2)
{Pour 2 gallon water from 3 gallon jug into 4 gallon jug}

Que-6: There are two water jugs with capacity 3 litre and 5 litre. Explain all the steps to
transfer 4 litre water in 5 litre jug.

Initial State: (0,0)

Goal State: (0,4)

Explanation: The following steps are taken:

1. Fill the 5-liter jug completely. (0,5)


2. Transfer 3 litters from a 5-liter jug to a 3-litre jug. (3,2)
3. Empty the 3-liter capacity jug. (0,2)
4. Transfer the remaining 2 litters from a 5-liter jug to a 3-liter jug. (2,0)
5. Now, fill the 5-liter jug fully. (2,5)
6. Pour 1 litre from a 5-liter jug into a 3-liter jug. (3,4)
7. There! We have 4 litres in the first jug, now empty the 2nd jug. (0,4)
Que-7: Explain 8 puzzle problem of AI using tree diagram.
 The 8 puzzle consists of eight numbered, movable tiles set in a 3x3 frame.
 One cell of the frame is always empty thus making it possible to move an adjacent
numbered tile into the empty cell.
 Such a puzzle is illustrated in following diagram.

 A solution to the problem is an appropriate sequence of moves, such as “move tile 5


to the right, move tile 7 to the left, move tile 6 to the down” etc…

 A move transforms one problem state into another state.


 The 8-puzzle is conveniently interpreted as having the following for moves.
Que-8: Give the differences between conventional problem solving and AI problem solving.

AI Problem solving Conventional Problem solving


1 It uses knowledgebase. It uses database.
2 It is based on reasons. It is based on numbers.
3 Solution steps are not clear. Solutions steps are clear.
4 It uses heuristic algorithm to solve the It uses general algorithm to solve the
problem. problem
5 Modifications are frequent. Modifications are rare.
6 It works on inferential technique. It works on repetition technique.
7 Results are satisfactory Results may not satisfactory.
8
AI Problem General Problem

AI Technique Knowledge
General Technique Data
base base
Solution
Solution

**Knowledgebase is collection of facts.

Que-9: Explain different types of Search Strategies.

There are two types of search strategy used to solve the problem in artificial intelligence.
1. Uninformed search / Blind search strategy
2. Informed search strategy / Heuristics search

1. Uninformed search strategy:


 It has no information about number of steps or path or cost from current state to goal
state.
 It can only distinguish between goal state and non-goal state.
 The word blind means it is not aware about whether the search process is moving
towards goal state or in opposite direction.
 If the search state generated is goal state then process stops else continues to
generate the next state.

There are main two types of uninformed searching or brute force searching.
a. Breadth First Search (BFS)
b. Depth First Search (DFS)

a. Breadth First Search Technique:

• BFS technique requires large memory space.


• Time complexity is increased in BFS.
• It has long pathways.
• It finds the minimal solution in case of multiple paths.
• Queue data structure is used to implement BFS.
b. Depth First search Technique:

 In DFS, instead of going on width, one branch of root node or tree is explored
one by one until the goal state is found.
 DFS explores each possible paths to find the solution.
 DFS requires less memory.
 Amount of time required is decreased.
 DFS can be trapped by following unfaithful path.
 No minimal solution is guaranteed by DFS.

2. Informed Search Strategy:


 It knows whether non-goal state is moving towards goal state or not.
 It is also known as heuristic search.
 It knows whether non-goal state is more promising than other non-goal state.
 It also finds out which non-goal state is closer to goal state.
 If the generated state is goal state then search process stops.

Que-10: Solve Following Tree example using BFS and DFS techniques. A is the initial state
and G is the Goal state.

Steps to solve using BFS technique


Step:1 start expanding from root node A.

Step:2 complete breadth of root A is generated by opening all children. (B, C, D)


Step:3 complete breadth of leftmost child is generated.

Step:4 generate the child of node C which is on right side of B.

Step:5 Check out about the goal. Here G is the Goal state so stops there and exit.

Steps to solve using DFS technique

Step-1: states are generated for root node A.

Step-2: depth of root node A is generated. (Only the leftmost child of root node A is generated
which is B.)

Step-3: depth of node B is generated. (node E)


Step-4: depth of node E is generated. (Node I)

Step-5: depth of node I is not generated. So backtrack to node B and generate the
depth. (node F)

Step-6: generate the depth of node A.(node C)

Step-7: generate depth of node C. (Node G, which is goal state)

‘]

Que-11: Give the differences between BFS and DFS searching techniques.

BFS DFS
1 It is Breadth First Search It is Depth First Search
2 It uses Data structure Queue. It uses data structure stack.
3 It requires more memory space. It requires less memory space.
4 It is time consuming. It optimizes the time.
5 It uses FIFO policy to search the goal It uses LIFO policy to search the goal.
6 It search path by traversing It search path by traversing vertical first
horizontal first and vertical next. and horizontal next.
7 It doesn’t uses backtracking. It uses backtracking.
Que-12: Explain a Hill Climbing Algorithm? Also explain state space diagram.

 State and value make up the two components of a hill climbing algorithm node.

Above figure is the representation of state space diagram. A state-space diagram


consists of various regions that can be explained as follows;

Local maximum:
A local maximum is a solution that surpasses other neighbouring solutions or states
but is not the best possible solution.

Global maximum:
This is the best possible solution achieved by the algorithm.
Current state:
This is the existing or present state.

Flat local maximum:


This is a flat region where the neighbouring solutions attain the same value.

Shoulder:
This is a plateau whose edge is stretching upwards.

 Large computational problems can be solved memory-effectively by using the hill


climbing algorithm.
 It considers both the current state and the state immediately nearby.
 Hill climbing is a heuristic strategy, or to put it another way. It is a search technique or
informed search technique that assigns various weights based on actual numbers to
distinct nodes, branches, and destinations in a path.
 The hill-climbing algorithm's key characteristics are its high input efficiency and
superior heuristic assignment.
 A hill-climbing algorithm is a local search algorithm that moves continuously upward
(increasing) until the best solution is attained.
 This algorithm comes to an end when the peak is reached.
 This algorithm has a node that comprises two parts: state and value.
 The process of continuous improvement of the current state of iteration can be
termed as climbing.
 This explains why the algorithm is termed as a hill-climbing algorithm.
 A hill-climbing algorithm’s objective is to attain an optimal state that is an upgrade of
the existing state.

Features of a hill climbing algorithm:


A hill-climbing algorithm has four main features:
a. It employs a greedy approach: This means that it moves in a direction in which the
cost function is optimized.
b. No Backtracking: A hill-climbing algorithm only works on the current state and
future states. It does not look at the previous states.
c. Feedback mechanism: The algorithm has a feedback mechanism that helps it decide
on the direction of movement (whether up or down the hill).
d. Incremental change: The algorithm improves the current solution by incremental
changes.

You might also like