Aiml Partb
Aiml Partb
1. Enumerate Classical “Water jug Problem”. Describe the state space for this problem
and also give the solution.
The Water Jug Problem typically involves two jugs with different capacities. The objective is to
measure a specific quantity of water by performing operations like filling a jug, emptying a jug, or
transferring water between the two jugs. The problem can be stated as follows:
You are given two jugs, one with a capacity of X litres and the other with a capacity of Y litres
You need to measure exactly Z litres of water using these two jugs.
The allowed operations are:
o Fill one of the jugs.
o Empty one of the jugs.
o Pour water from one jug into another until one jug is either full or empty.
2. Solve the given problem. Describe the operators involved in it. Consider a Water Jug
Problem : You are given two jugs, a 4-gallon one and a 3-gallon one. Neither has any
measuring markers on it. There is a pump that can be used to fill the jugs with water.
How can you get exactly 2 gallons of water into the 4-gallon jug ? Explicit Assumptions:
A jug can be filled from the pump, water can be poured out of a jug onto the ground,
water can be poured from one jug to another and that there are no other measuring
devices available.
The Water Jug Problem is a classic example of a constraint satisfaction problem that can be
solved using state-space search. The given problem involves two jugs:
A 4-gallon jug.
A 3-gallon jug.
A pump to fill the jugs.
No other measuring tools available.
Operators Involved
1. Fill a Jug: Completely fill either the 4-gallon or 3-gallon jug using the pump.
2. Empty a Jug: Completely empty either jug onto the ground.
3. Pour Water from One Jug to Another:
o Water can be poured from the 4-gallon jug to the 3-gallon jug until either the 3-gallon
jug is full or the 4-gallon jug is empty.
o Water can be poured from the 3-gallon jug to the 4-gallon jug until either the 4-gallon
jug is full or the 3-gallon jug is empty.
Step-by-Step Process
6. Pour the 2 gallons from the 3-gallon jug into the 4-gallon jug → (2, 0)
3. Define the following problems. What types of control strategy is used in the following
problem. i. The Tower of Hanoi ii. Crypto-arithmetic iii. The Missionaries and
cannibals problems iv. 8-puzzle problem
(i)The Tower of Hanoi
Problem Definition
The Tower of Hanoi is a mathematical puzzle involving three pegs and n disks of different
sizes. The objective is to move all disks from the source peg to the destination peg while
following these rules:
(ii)Crypto-Arithmetic
Problem Definition
Crypto-arithmetic problems involve assigning unique numerical values to letters such that a
given arithmetic equation holds true. For example:
SEND
+ MORE
--------
MONEY
Each letter represents a unique digit (0-9), and no two letters have the same value.
In this problem, three missionaries and three cannibals must cross a river using a boat. The
boat can hold at most two people at a time. The challenge is to ensure that at no point do the
cannibals outnumber the missionaries on either side, as they would eat them.
Control Strategy Used
State Space Search: The problem is modeled as a set of states, with valid moves as
transitions.
Breadth-First Search (BFS): Ensures the shortest path solution.
Depth-First Search (DFS): Explores possible solutions deeply before backtracking.
Heuristic Search (A Algorithm):* Can be used to optimize pathfinding.
The 8-puzzle consists of a 3×3 grid with eight numbered tiles and one empty space. The
objective is to rearrange the tiles from an initial state to a goal state by sliding tiles into the
empty space.
Uninformed search (also called blind search) refers to search strategies that do not use any
domain-specific knowledge about the problem. These methods systematically explore the
search space but do not prioritize paths based on how "close" they are to the goal.
Explores all nodes at the current depth before moving to the next depth.
Uses a queue (FIFO) data structure.
Guarantees the shortest path in an unweighted graph.
Example:
mathematica
CopyEdit
A
/\
B C
/\ \
D E F
Pros:
Cons:
High memory usage (stores all nodes at a level before moving deeper).
Slow in large or deep search spaces.
Example:
Using the same graph as BFS, DFS explores one path deeply before backtracking:
Order of exploration (one possible order): A → B → D → E → C → F
Pros:
Cons:
May get stuck in infinite loops if cycles exist (without cycle detection).
Not guaranteed to find the shortest path.
3. Depth-Limited Search (DLS)
Description:
Similar to DFS but with a maximum depth limit to prevent infinite recursion.
Useful when the depth of the solution is known.
Example:
If the limit is 2, the search will only explore up to depth 2, ignoring deeper nodes.
Pros:
Cons:
Example:
Pros:
Cons:
Steepest-Ascent Hill Climbing (also called Greedy Hill Climbing) is a variant of hill
climbing that always moves to the best possible neighbor (i.e., the neighbor with the
highest heuristic value). It does not consider less promising moves
Steps:
Advantages
✔ Faster than simple hill climbing (chooses the best option at each step).
✔ Uses less memory compared to exhaustive search algorithms.
✔ Good for small or well-behaved search spaces.
Disadvantages
A Search Algorithm*
A* (A-star) is one of the most powerful and widely used informed search algorithms. It is
used in pathfinding and graph traversal, efficiently finding the shortest path from a start
node to a goal node.
Key Features
Combines Best-First Search (Greedy Search) and Uniform Cost Search (UCS).
Uses a heuristic function to estimate the cost to reach the goal.
Guarantees the shortest path (optimality) if the heuristic is admissible and consistent.
Algorithm of A Search*
Steps of A Search:*
1. Initialize:
o Put the start node in the open list (priority queue).
o Set g(start)=0g(\text{start}) = 0g(start)=0 and f(start)=h(start)f(\text{start}) = h(\
text{start})f(start)=h(start).
4. Repeat until the goal node is reached or the open list is empty (failure).
7. Explain AO* algorithm with a suitable example. State the limitations in the
algorithm?
The AO* (AND-OR) algorithm is a search algorithm used in problem-solving when a solution
consists of multiple subproblems. Unlike traditional search methods (like A), AO* is designed for
problems that can be broken down into AND & OR nodes.
Key Concepts
AND nodes: Multiple branches must be explored together to form a valid solution.
OR nodes: Only one branch needs to be explored to reach a solution.
Uses a heuristic function h(n)h(n)h(n): Estimates the cost from a node to the goal.
Backtracking & Dynamic Programming: AO* updates costs dynamically as new
information is found.
Execution Steps
Limitations of AO*
❌ High Computational Cost: Updates require re-evaluating the entire solution tree.
❌ Limited by Heuristic Quality: Performance depends on an accurate heuristic function.
❌ Complexity in AND Nodes: Requires solving all subproblems, increasing search depth.
❌ Not Suitable for All Problems: Works best for decomposable problems (e.g., hierarchical
planning).
8. Explain the nature of heuristics with example. What is the effect of heuristics
accuracy?
Characteristics of Heuristics
The accuracy of the heuristic directly impacts the efficiency and optimality of a search
algorithm.
Hill climbing is a local search algorithm used for optimization problems, where the goal is
to find the best solution by iteratively improving a candidate solution based on a heuristic
function. There are several variants of hill climbing that address its limitations and improve
efficiency.
1. Simple Hill Climbing
Description:
Algorithm Steps:
Advantages:
✔ Simple to implement
✔ Requires less memory
Disadvantages:
Algorithm Steps:
Advantages:
Disadvantages:
Description:
Algorithm Steps:
Advantages:
Disadvantages:
Description:
A variation of stochastic hill climbing, but selects the first better move it finds rather than
evaluating all neighbors.
Algorithm Steps:
Advantages:
Disadvantages:
Description:
Repeatedly restarts the search from a new random state if stuck in local maxima.
Increases the chances of finding the global optimum.
Algorithm Steps:
Advantages:
Disadvantages:
Description:
Algorithm Steps:
Advantages:
10. Discuss about constraint satisfaction problem with a algorithm for solving a crypt
arithmetic Problem. . Solve the following Crypt arithmetic problem using constraints
satisfaction search procedure. CROSS +ROADS ------------ DANGER ----------------
CROSS+ROADS=DANGER\text{CROSS} + \text{ROADS} = \
text{DANGER}CROSS+ROADS=DANGER
we will use the Constraint Satisfaction Search (CSP) procedure, which involves:
C,R,O,S,A,D,N,G,EC, R, O, S, A, D, N, G, EC,R,O,S,A,D,N,G,E
CROSS
+ ROADS
------------
DANGER
Additional constraints:
Each digit (0-9) is unique.
Carries are handled for column-wise addition.
Using Backtracking & Constraint Propagation, we systematically assign digits and check
constraints.
Solution Found:
98233
+ 76423
--------
174656
Letter Digit
C 9
R 8
O 2
S 3
A 6
D 7
N 4
G 5
E 6