AI Real
AI Real
Definitions:
• AI is the science and engineering of making intelligent machines.
• AI is the study of agents that perceive the environment and take
actions to maximize the chances of achieving goals.
• AI is the simulation of human intelligence processes by machines,
especially computer systems.
Goals of AI:
• Create expert systems that exhibit intelligent behavior.
• Implement human intelligence in machines.
• Enable machines to learn from experience.
• Develop systems that can solve complex real-world problems.
------------------------------------------------------------
2) AI Techniques:
An AI technique should:
• Use knowledge effectively.
• Be flexible and adaptable.
2
Major AI Techniques:
1. Search Techniques:
Search methods are used to explore possible solutions to find the best
one.
Examples:
• Breadth First Search (BFS)
• Depth First Search (DFS)
• A* Algorithm
• Best First Search
Search techniques are widely used in problem solving and path finding.
2. Knowledge Representation:
It is the method of representing information about the world in a form
that a computer system can use to solve complex tasks.
Examples:
• Predicate Logic
• Semantic Networks
• Frames
• Production Rules
4. Learning Techniques:
Learning enables systems to improve performance based on experience.
Examples:
• Supervised Learning
• Unsupervised Learning
• Reinforcement Learning
3
• Neural Networks
5. Expert Systems:
Expert systems use knowledge and inference rules to solve problems in a
specific domain.
Components:
• Knowledge Base
• Inference Engine
7. Fuzzy Logic:
Fuzzy logic handles uncertainty and imprecision in data.
Answer:
------------------------------------------------------------
Weak AI, also known as Narrow AI, is a type of artificial intelligence that
is designed to perform a specific task or a limited range of tasks. It does
not possess general intelligence or self-awareness. It operates under a
predefined set of rules and algorithms.
Characteristics:
• Designed for a single specific task.
• Does not have consciousness or emotions.
• Cannot perform tasks outside its programmed domain.
• Uses domain-specific knowledge.
• Works based on data and algorithms.
4
Examples:
• Chatbots
• Recommendation systems
• Spam filters
• Voice assistants
• Chess-playing programs
In Weak AI, the system only simulates human intelligence but does not
actually understand or think like a human.
------------------------------------------------------------
Characteristics:
• Possesses general intelligence.
• Can reason, plan, learn, and solve problems.
• Has the ability to understand and adapt to new situations.
• Can transfer knowledge from one domain to another.
• Theoretically capable of self-awareness and consciousness.
Examples:
• Fully autonomous intelligent systems (theoretical)
• Human-like robots with independent reasoning ability
------------------------------------------------------------
Weak AI:
• Task-specific intelligence
5
• Limited scope
• No self-awareness
• Exists in real-world applications
Strong AI:
• Human-level intelligence
• Broad scope of tasks
• Theoretically self-aware
• Still under research
Answer:
------------------------------------------------------------
The interrogator communicates with both the human and the machine
through a text-based interface (such as a keyboard and screen). The
interrogator does not know which participant is human and which is
machine.
6
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Conclusion:
------------------------------------------------------------------------------------------------
Answer:
------------------------------------------------------------
These tasks are easy for humans but difficult for machines. They require
perception, understanding, and reasoning.
a) Perception:
• Computer Vision – recognizing objects, faces, and patterns.
• Speech Recognition – understanding spoken language.
c) Robotics:
• Movement and manipulation.
• Navigation and object handling.
8
------------------------------------------------------------
2) Formal Tasks:
a) Game Playing:
• Chess
• Checkers
• Tic-Tac-Toe
------------------------------------------------------------
3) Expert Tasks:
a) Medical Diagnosis:
• Identifying diseases based on symptoms.
• Suggesting treatments.
b) Engineering Design:
• Circuit design
• Mechanical system design.
c) Financial Analysis:
• Stock market prediction.
• Risk assessment.
------------------------------------------------------------
a) Autonomous Vehicles
b) Industrial Automation
c) Intelligent Agents
These systems must sense the environment, analyze data, and take
actions.
------------------------------------------------------------
Conclusion:
-----------------------------------------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Expert Systems:
Applications:
• Medical diagnosis
• Fault detection in machines
• Financial advisory systems
• Legal advisory systems
------------------------------------------------------------
Applications:
• Language translation systems
• Chatbots and virtual assistants
• Sentiment analysis
• Speech recognition systems
------------------------------------------------------------
3) Robotics:
Applications:
• Industrial robots for manufacturing
• Automated warehouses
• Space exploration robots
• Service robots
------------------------------------------------------------
4) Computer Vision:
Applications:
• Face recognition systems
• Object detection
• Medical image analysis
• Surveillance systems
------------------------------------------------------------
5) Game Playing:
Applications:
• Chess programs
• Online gaming bots
• Strategy-based games
------------------------------------------------------------
6) Healthcare:
Applications:
• Disease prediction
• Drug discovery
• Personalized treatment
• Medical imaging analysis
------------------------------------------------------------
Applications:
• Fraud detection
• Credit scoring
12
------------------------------------------------------------
8) Education:
Applications:
• Intelligent tutoring systems
• Automated grading
• Personalized learning platforms
CH 2
Q.1 What is State Space of a Problem?
Answer:
------------------------------------------------------------
1) State:
Example:
In the 8-puzzle problem, each arrangement of tiles on the board
represents a different state.
------------------------------------------------------------
13
2) State Space:
Thus, state space = {All states reachable from initial state using valid
operators}
------------------------------------------------------------
------------------------------------------------------------
4) Example:
All these possible combinations form the state space of the problem.
------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Problem Definition:
The objective is to reach a specified goal state from a given initial state
by sliding tiles into the blank space.
------------------------------------------------------------
2) Components of 8–Puzzle:
a) State:
A state represents a particular arrangement of the 8 tiles and the blank
space on the board.
Example:
Initial State:
283
164
7_5
Goal State:
123
8_4
765
------------------------------------------------------------
b) Initial State:
The starting configuration of the puzzle.
c) Goal State:
The desired configuration to be achieved.
d) Operators (Actions):
Possible moves of the blank space:
• Move blank up
• Move blank down
• Move blank left
• Move blank right
------------------------------------------------------------
3) State Space:
------------------------------------------------------------
4) Representation:
------------------------------------------------------------
16
5) Solution Techniques:
------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Problem Definition:
Example:
Jug A = 4 liters
Jug B = 3 liters
Goal = Measure exactly 2 liters of water.
17
------------------------------------------------------------
2) State Representation:
------------------------------------------------------------
3) Operators (Actions):
------------------------------------------------------------
4) State Space:
------------------------------------------------------------
Initial: (0,0)
1. Fill Jug B → (0,3)
2. Pour B to A → (3,0)
3. Fill Jug B → (3,3)
4. Pour B to A → (4,2)
5. Empty Jug A → (0,2)
6. Pour B to A → (2,0)
------------------------------------------------------------
6) Nature of Problem:
------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Problem Definition:
Three missionaries and three cannibals are on the left bank of a river.
They must cross to the right bank using a boat.
Conditions:
• The boat can carry at most two persons at a time.
• At no time on either bank should the number of cannibals exceed the
number of missionaries (if missionaries are present).
19
------------------------------------------------------------
2) State Representation:
Where:
M = Number of missionaries on the left bank
C = Number of cannibals on the left bank
B = Position of boat (Left or Right)
Initial State:
(3, 3, Left)
Goal State:
(0, 0, Right)
------------------------------------------------------------
20
4) State Space:
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Q. Explain Monkey and Banana Problem.
Answer:
The Monkey and Banana problem is a classical Artificial Intelligence
problem used to explain state space representation and problem solving
using search techniques.
------------------------------------------------------------
1) Problem Definition:
21
Conditions:
• The monkey cannot reach the bananas directly.
• The monkey can move around the room.
• The monkey can push the box to any position.
• The monkey can climb on the box.
• The monkey can grasp the bananas if it is on the box under the
bananas.
------------------------------------------------------------
2) State Representation:
Where:
• Monkey_Position = position of monkey in the room
• Box_Position = position of box
• Monkey_Status = OnFloor or OnBox
• Has_Banana = True or False
Initial State:
Monkey is on the floor, box is at a different position, and monkey does
not have banana.
Goal State:
Has_Banana = True
------------------------------------------------------------
3) Operators (Actions):
4) State Space:
The solution is found by searching from initial state to goal state using
valid operators.
------------------------------------
------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Components of an AI Problem:
------------------------------------------------------------
2) Characteristics of AI Problems:
1. Decomposability:
A problem may or may not be divided into smaller sub-problems.
Example: Tower of Hanoi is decomposable into smaller similar problems.
2. Nature of Steps:
Steps may be:
• Ignorable – Once done, no need to reconsider.
• Recoverable – Can be undone.
• Irrecoverable – Cannot be undone.
3. Predictability:
The environment may be:
• Deterministic – Output is predictable.
• Non-deterministic – Output is uncertain.
4. Static vs Dynamic:
• Static – Environment does not change during problem solving.
• Dynamic – Environment changes over time.
5. Discrete vs Continuous:
• Discrete – Finite number of states.
• Continuous – Infinite possible states.
6. Known vs Unknown:
• Known – All rules and effects are known.
• Unknown – Rules are not completely known.
------------------------------------------------------------
3) Tower of Hanoi Problem:
Problem Definition:
There are three pegs (A, B, C) and N disks of different sizes placed on peg
A in decreasing size order. The objective is to move all disks from peg A
to peg C using peg B as auxiliary.
Rules:
• Only one disk can be moved at a time.
• A larger disk cannot be placed on a smaller disk.
------------------------------------------------------------
4) Representation of Tower of Hanoi:
Initial State:
All disks on peg A.
Goal State:
All disks on peg C.
Operators:
Move top disk from one peg to another (if rules are satisfied).
State Space:
All possible legal arrangements of disks on three pegs.
------------------------------------------------------------
5) Characteristics of Tower of Hanoi:
• Decomposable Problem:
The problem of N disks can be reduced to:
- Move N-1 disks to auxiliary peg.
- Move largest disk to destination peg.
- Move N-1 disks to destination peg.
• Deterministic:
25
• Static:
Environment does not change during solving.
• Fully Observable:
All disk positions are known.
• Discrete:
Finite number of states.
• Recoverable:
Moves can be undone.
• Optimal Solution:
Minimum moves required = 2^N − 1
------------------------------------------------------------
6) Nature of AI in Tower of Hanoi:
------------------------------------------------------------
Answer:
1) Production System:
IF <condition>
THEN <action>
When the condition part matches the current state in working memory,
the rule is fired and the action part is executed.
------------------------------------------------------------
2) Components of Production System:
1. Production Rules:
- Represented in IF–THEN form.
- Encode knowledge of the problem domain.
2. Working Memory:
- Contains facts describing the current state of the problem.
- Updated after each rule execution.
------------------------------------------------------------
3) Production System Cycle (Recognize–Act Cycle):
------------------------------------------------------------
4) Production System Analysis:
27
1. Monotonic vs Non-Monotonic:
2. Deterministic vs Non-Deterministic:
Deterministic:
• Only one rule can be applied at a time.
• Clear and predictable behavior.
Non-Deterministic:
• Multiple rules may be applicable.
• Requires conflict resolution strategy.
Commutative:
• Order of applying rules does not affect final result.
Partially Commutative:
• Order of rule application may affect intermediate states but not final
goal.
------------------------------------------------------------
5) Classification of Production Systems:
------------------------------------------------------------
6) Advantages of Production System:
------------------------------------------------------------
Answer:
------------------------------------------------------------
1) Need for Control Strategy:
------------------------------------------------------------
2) Working of Control Strategy:
1. Match Phase:
All rules whose conditions match the current working memory are
identified.
3. Act Phase:
The selected rule is executed and working memory is updated.
------------------------------------------------------------
3) Types of Control Strategies:
2. Priority-Based Strategy:
Each rule is assigned priority. Higher priority rule is selected.
3. Specificity Strategy:
The rule with more specific conditions (more detailed match) is
selected.
4. Recency Strategy:
Rule that uses the most recently added facts is selected.
30
5. Random Selection:
One rule is selected randomly from conflict set.
6. Depth-First Strategy:
Apply newly generated rules first (stack-based).
7. Breadth-First Strategy:
Apply older rules first (queue-based).
------------------------------------------------------------
4) Importance in AI:
------------------------------------------------------------
Q. Explain Informed and Uninformed Search in Artificial
Intelligence.
Answer:
------------------------------------------------------------
1) Uninformed Search (Blind Search):
• Successor function
• Goal test
• Path cost
Characteristics:
• No heuristic information.
• Explores blindly.
• May be inefficient for large state spaces.
Advantages:
• Simple to implement.
• Guaranteed solution (BFS, UCS).
Disadvantages:
• High time and space complexity.
• Not efficient for complex problems.
32
------------------------------------------------------------
2) Informed Search (Heuristic Search):
A heuristic function h(n) estimates the cost from current node to the
goal.
Characteristics:
• Uses problem-specific knowledge.
• More efficient than uninformed search.
• Reduces search space.
2. A* Search Algorithm:
• Uses evaluation function:
f(n) = g(n) + h(n)
where,
g(n) = cost from start to node
h(n) = estimated cost to goal
• Complete and optimal if heuristic is admissible.
3. Hill Climbing:
• Selects best neighbor.
• May get stuck in local maxima.
4. Beam Search:
• Limits number of nodes at each level.
Advantages:
• Faster solution.
• Efficient use of memory.
• Suitable for complex problems.
33
Disadvantages:
• Quality depends on heuristic function.
• May not always guarantee optimal solution.
------------------------------------------------------------
3) Difference between Informed and Uninformed Search:
Uninformed Search:
• No heuristic knowledge.
• Explores entire search space.
• Less efficient.
• Examples: BFS, DFS.
Informed Search:
• Uses heuristic function.
• Directed toward goal.
• More efficient.
• Examples: A*, Greedy search.
------------------------------------------------------------
Q. Compare DFS and BFS in detail with algorithms.
Answer:
Depth First Search (DFS) and Breadth First Search (BFS) are uninformed
search techniques used to explore the state space in Artificial
Intelligence.
------------------------------------------------------------
1) Breadth First Search (BFS):
Definition:
Breadth First Search explores the search tree level by level. It expands all
nodes at one depth before moving to the next depth level.
Algorithm of BFS:
Properties of BFS:
Where:
b = branching factor
d = depth of goal node
Advantages:
• Finds shortest path.
• Simple to implement.
Disadvantages:
• Requires large memory.
• Not suitable for deep search space.
------------------------------------------------------------
2) Depth First Search (DFS):
Definition:
Depth First Search explores the deepest node first before backtracking.
It goes deep along one branch until it reaches a dead end.
Algorithm of DFS:
Properties of DFS:
• Completeness: No (may get stuck in infinite path).
• Optimality: No.
• Time Complexity: O(b^m)
• Space Complexity: O(bm)
Where:
b = branching factor
m = maximum depth of tree
Advantages:
• Requires less memory.
• Simple and faster for deep solutions.
Disadvantages:
• May not find shortest path.
• Can get stuck in loops.
------------------------------------------------------------
3) Difference Between BFS and DFS:
1. Search Strategy:
BFS – Level by level.
DFS – Depth wise.
2. Data Structure:
BFS – Queue.
DFS – Stack.
3. Completeness:
36
BFS – Complete.
DFS – Not always complete.
4. Optimality:
BFS – Optimal (unit cost).
DFS – Not optimal.
5. Memory Requirement:
BFS – High.
DFS – Low.
6. Suitable For:
BFS – Shallow solutions.
DFS – Deep solutions with limited memory.
------------------------------------------------------------
BFS explores nodes level by level and guarantees shortest path but
requires more memory. DFS explores deeply with less memory but does
not guarantee optimal or complete solution. The choice depends on
problem characteristics.
A heuristic function h(n) estimates the cost or distance from the current
node to the goal node.
------------------------------------------------------------
1) Heuristic Function:
Example:
In 8–Puzzle problem:
• Number of misplaced tiles
• Manhattan distance
------------------------------------------------------------
2) Need for Heuristic Search:
------------------------------------------------------------
3) Heuristic Search Techniques:
------------------------------------------------------------
2) Hill Climbing:
Types:
• Simple Hill Climbing
• Steepest Ascent Hill Climbing
• Stochastic Hill Climbing
38
Limitations:
• May get stuck in local maxima.
• Plateau problem.
• No backtracking.
------------------------------------------------------------
Evaluation function:
f(n) = h(n)
------------------------------------------------------------
------------------------------------------------------------
5) A* Search Algorithm:
Evaluation function:
f(n) = g(n) + h(n)
Where:
g(n) = cost from start to current node
h(n) = estimated cost to goal
Properties:
• Complete.
• Optimal (if heuristic is admissible).
• Widely used in AI applications.
39
------------------------------------------------------------
6) Beam Search:
• Similar to BFS.
• Keeps only limited number of best nodes at each level.
• Reduces memory usage.
------------------------------------------------------------
4) Advantages of Heuristic Search:
------------------------------------------------------------
5) Disadvantages:
------------------------------------------------------------
Conclusion:
Heuristic search uses domain knowledge to guide the search process
efficiently. Techniques like Hill Climbing, Best First Search, Greedy
Search, and A* significantly reduce search complexity and are widely
used in solving AI problems.
------------------------------------------------------------
1) Basic Idea:
------------------------------------------------------------
2) Algorithm of Hill Climbing:
------------------------------------------------------------
3) Types of Hill Climbing:
------------------------------------------------------------
4) Problems in Hill Climbing:
1) Local Maximum:
• Algorithm stops at a peak which is not global maximum.
2) Plateau:
• Flat area where neighboring states have same value.
• Algorithm cannot decide direction.
3) Ridge:
• Path requires diagonal movement but algorithm moves only in one
direction.
------------------------------------------------------------
5) Advantages:
• Simple to implement.
• Requires less memory.
• Fast for small problems.
------------------------------------------------------------
6) Disadvantages:
• Not complete.
• Not optimal.
• Can get stuck in local maxima.
• No backtracking.
------------------------------------------------------------
7) Applications:
• 8–Puzzle problem
• Traveling Salesman Problem (approximate)
• Scheduling problems
• Optimization problems
Conclusion:
42
Answer:
It combines the advantages of both Depth First Search and Breadth First
Search by selecting the best node using heuristic information.
------------------------------------------------------------
1) Basic Idea:
Evaluation Function:
f(n) = h(n)
Where:
h(n) = estimated cost from node n to goal.
------------------------------------------------------------
2) Algorithm of Best First Search:
------------------------------------------------------------
3) Working Example (Concept):
At each step:
• Calculate heuristic value for all frontier nodes.
• Select node with smallest heuristic value.
• Continue until goal is reached.
------------------------------------------------------------
4) Properties:
------------------------------------------------------------
5) Advantages:
------------------------------------------------------------
6) Disadvantages:
------------------------------------------------------------
44
7) Applications:
------------------------------------------------------------
8) Relation with Other Algorithms:
Conclusion:
Best First Search is a heuristic-based search algorithm that selects the
most promising node using heuristic evaluation. It is more efficient than
blind search but does not always guarantee optimal solution.
Answer:
A* (A-Star) Search Algorithm is one of the most efficient and widely used
informed search techniques in Artificial Intelligence. It combines the
advantages of Uniform Cost Search and Greedy Best First Search.
It uses both:
• Actual path cost from start node
• Heuristic estimate to goal
------------------------------------------------------------
1) Evaluation Function:
Where:
45
------------------------------------------------------------
2) Algorithm of A* Search:
------------------------------------------------------------
3) Example:
(S)
/ \
1/ \4
(A) (B)
3 \ /5
(G)
Heuristic values:
46
h(S) = 7
h(A) = 6
h(B) = 2
h(G) = 0
Edge Costs:
S→A=1
S→B=4
A→G=3
B→G=5
------------------------------------------------------------
Step 1:
Start at S
g(S) = 0
f(S) = g + h = 0 + 7 = 7
Expand S.
------------------------------------------------------------
Step 2:
Successors:
For A:
g(A) = 0 + 1 = 1
f(A) = 1 + 6 = 7
For B:
g(B) = 0 + 4 = 4
f(B) = 4 + 2 = 6
------------------------------------------------------------
Step 3:
Expand B.
47
Successor:
For G through B:
g(G) = 4 + 5 = 9
f(G) = 9 + 0 = 9
Select A (f=7)
------------------------------------------------------------
Step 4:
Expand A.
Successor:
For G through A:
g(G) = 1 + 3 = 4
f(G) = 4 + 0 = 4
------------------------------------------------------------
Step 5:
Optimal Path:
S→A→G
Total Cost = 4
------------------------------------------------------------
4) Properties of A*:
------------------------------------------------------------
5) Conditions for Optimality:
------------------------------------------------------------
6) Advantages:
------------------------------------------------------------
7) Disadvantages:
------------------------------------------------------------
Conclusion:
Answer:
------------------------------------------------------------
1) Concept of AND–OR Graph:
1) OR Node:
• Represents alternative methods to solve a problem.
• Solving any one child node is sufficient.
2) AND Node:
• Represents decomposition into multiple sub-problems.
• All child nodes must be solved to solve the parent node.
------------------------------------------------------------
2) Structure of AND–OR Graph:
50
------------------------------------------------------------
3) Example of Problem Reduction:
Method 1:
P → A AND B
(Both A and B must be true)
Method 2:
P→C
(Only C is sufficient)
Graphically:
P
/ \
(AND) C
/ \
A B
Here:
• P is an OR node (choose either method).
• A and B are AND nodes (both required).
If C is solved, P is solved.
If both A and B are solved, P is also solved.
------------------------------------------------------------
4) Algorithm Used:
For OR node:
Cost = minimum cost of any child.
------------------------------------------------------------
5) Difference Between OR Graph and AND–OR Graph:
OR Graph:
• Only one successor needs to be solved.
• Used in normal search problems.
AND–OR Graph:
• Some nodes require solving multiple sub-problems.
• Used in problem reduction.
------------------------------------------------------------
6) Applications:
• Theorem proving
• Planning problems
• Game playing
• Expert systems
------------------------------------------------------------
7) Advantages:
------------------------------------------------------------
Conclusion:
Answer:
------------------------------------------------------------
1) Basic Idea:
Thus, it reduces the gap between “means” (current state) and “end”
(goal state).
------------------------------------------------------------
2) Steps of Means–End Analysis:
53
------------------------------------------------------------
3) Representation:
• Initial State
• Goal State
• Operators
• Difference function
• Preconditions of operators
------------------------------------------------------------
4) Example: Water Jug Problem
Difference:
Need 2 liters in jug A.
Operator selected:
Pour water to get required amount.
If jug is empty:
Precondition: Fill jug first.
Thus:
• Fill jug
• Pour water
• Reduce difference step by step
• Reach goal
54
5) Characteristics:
• Goal-oriented approach.
• Breaks problem into sub-problems.
• Uses difference reduction strategy.
• Combines search and planning.
------------------------------------------------------------
6) Advantages:
• Systematic approach.
• Efficient for structured problems.
• Reduces unnecessary exploration.
• Suitable for theorem proving and puzzle solving.
------------------------------------------------------------
7) Disadvantages:
------------------------------------------------------------
8) Applications:
------------------------------------------------------------
Conclusion:
Ch:7
------------------------------------------------------------
2) Components of Planning Problem:
1) Initial State:
• Describes the current situation of the environment.
• Represented using facts or predicates.
2) Goal State:
• Describes the desired situation to be achieved.
• Specifies conditions that must be true.
3) Actions (Operators):
56
4) State Space:
• All possible states reachable from the initial state.
5) Plan:
• A sequence of actions that leads from initial state to goal state.
------------------------------------------------------------
3) Example:
Initial State:
On(A, Table), On(B, Table), Clear(A), Clear(B)
Goal State:
On(A, B)
Action:
Stack(A, B)
Preconditions:
Clear(A), Clear(B), On(A, Table)
Effects:
Add: On(A, B)
Delete: On(A, Table), Clear(B)
------------------------------------------------------------
4) Types of Planning:
------------------------------------------------------------
5) Difference between Planning and Search Procedure:
1) Nature:
Search:
• General problem-solving technique.
• Explores state space blindly or heuristically.
Planning:
• Goal-directed action selection.
• Focuses on action representation and reasoning.
------------------------------------------------------------
2) Representation:
Search:
• States and operators.
• No detailed action description required.
Planning:
• Actions have preconditions and effects.
• Uses logical representation.
------------------------------------------------------------
3) Goal Handling:
Search:
• Goal test checks if goal state is reached.
Planning:
• Planner constructs a sequence of actions that satisfies goal conditions.
58
------------------------------------------------------------
4) Efficiency:
Search:
• May explore large state space.
• Less structured.
Planning:
• More structured.
• Uses domain knowledge to reduce search.
------------------------------------------------------------
5) Application:
Search:
• Puzzle solving, path finding.
Planning:
• Robotics, scheduling, automated reasoning.
------------------------------------------------------------
6) Conclusion:
Answer:
------------------------------------------------------------
1) Basic Idea:
------------------------------------------------------------
2) Components:
1) Initial State
2) Goal State
3) Actions (Operators) with:
• Preconditions
• Add list
• Delete list
4) Goal Stack
------------------------------------------------------------
3) Working Procedure (Algorithm):
------------------------------------------------------------
4) Example: Block World Problem
Initial State:
On(A, Table)
On(B, Table)
Clear(A)
Clear(B)
Goal:
On(A, B)
Step 1:
Push Goal: On(A, B)
Step 2:
Find operator Stack(A, B)
Stack contains:
On(A, B)
Stack(A, B)
Push Preconditions:
Clear(A)
Clear(B)
On(A, Table)
Stack becomes:
On(A, B)
Stack(A, B)
On(A, Table)
Clear(B)
Clear(A)
Step 3:
Check preconditions:
If satisfied, apply Stack(A, B)
61
Update state:
Add: On(A, B)
Delete: On(A, Table), Clear(B)
Goal achieved.
------------------------------------------------------------
5) Handling Multiple Goals:
Example:
Goal1: On(A, B)
Goal2: On(B, C)
Procedure:
• Push all goals onto stack.
• Solve top goal first.
• After achieving one goal, move to next.
• If achieving one goal destroys another, re-planning is required.
------------------------------------------------------------
6) Time Complexity:
Let:
b = branching factor (number of possible operators)
d = depth of goal decomposition
Because planner may explore many possible operator choices for each
sub-goal.
Space Complexity:
O(d) (stack depth)
62
------------------------------------------------------------
7) Advantages:
------------------------------------------------------------
8) Disadvantages:
------------------------------------------------------------
Conclusion:
Answer:
1) Introduction:
------------------------------------------------------------
2) Basic Idea:
------------------------------------------------------------
3) Components of Hierarchical Planning:
1) Initial State
• Description of the current world state.
2) Goal State
• Desired state to be achieved.
3) High-Level Tasks
• Abstract actions (e.g., “Travel to city”).
5) Primitive Actions
• Basic executable actions with:
- Preconditions
- Add list
- Delete list
------------------------------------------------------------
4) Working Procedure:
------------------------------------------------------------
5) Example:
High-Level Tasks:
1. Book Venue
2. Invite Speakers
3. Arrange Catering
Decomposition:
Book Venue →
• Check availability
• Make payment
Invite Speakers →
• Send emails
• Confirm responses
Arrange Catering →
• Select menu
• Confirm order
------------------------------------------------------------
6) Types of Hierarchical Planning:
------------------------------------------------------------
7) Advantages:
------------------------------------------------------------
8) Disadvantages:
------------------------------------------------------------
9) Difference from Classical Planning:
Classical Planning:
• Works at primitive action level.
• Searches state space directly.
Hierarchical Planning:
• Uses abstraction levels.
• Decomposes tasks before execution.
• More structured and efficient.
------------------------------------------------------------
Conclusion:
Answer:
1) Introduction:
• Chess
• Tic-Tac-Toe
• Checkers
• Connect Four
It is used when:
• One player tries to maximize the score.
• The opponent tries to minimize the score.
------------------------------------------------------------
2) Basic Idea:
1) MAX Player
• Tries to maximize the score.
• Chooses the move with highest value.
2) MIN Player
• Tries to minimize the score.
• Chooses the move with lowest value.
The algorithm explores the game tree and selects the optimal move.
------------------------------------------------------------
Levels of tree:
• Root → current state
• Internal nodes → possible moves
• Leaf nodes → final states
0 = draw
-1 = loss
------------------------------------------------------------
4) Working Principle:
Step 1:
Generate the game tree.
Step 2:
Evaluate leaf nodes using utility function.
Step 3:
Propagate values upward.
Step 4:
MAX nodes choose maximum value.
Step 5:
MIN nodes choose minimum value.
------------------------------------------------------------
5) Example:
MAX
/ \
MIN MIN
/ \ / \
3 5 2 9
Left subtree:
MIN(3,5) = 3
Right subtree:
68
MIN(2,9) = 2
MAX(3,2) = 3
------------------------------------------------------------
6) Minimax Algorithm:
2. If maximizingPlayer = TRUE:
bestValue = -∞
for each child of node:
value = MINIMAX(child, depth-1, FALSE)
bestValue = max(bestValue, value)
return bestValue
3. If maximizingPlayer = FALSE:
bestValue = +∞
for each child of node:
value = MINIMAX(child, depth-1, TRUE)
bestValue = min(bestValue, value)
return bestValue
------------------------------------------------------------
Let:
b = branching factor
d = depth of tree
Time Complexity:
69
O(b^d)
Space Complexity:
O(bd)
------------------------------------------------------------
8) Advantages:
------------------------------------------------------------
9) Disadvantages:
------------------------------------------------------------
Benefits:
• Reduces number of nodes evaluated.
• Same optimal result as Minimax.
• Faster performance.
------------------------------------------------------------
11) Applications:
• Tic-Tac-Toe AI
• Game theory
• Strategic decision making
------------------------------------------------------------
Conclusion:
Answer:
1) Introduction:
Alpha–Beta pruning does not change the final result of the Minimax
algorithm; it only speeds up the process.
------------------------------------------------------------
2) Basic Idea:
Alpha (α):
• Best value that the MAX player can guarantee so far.
• Represents the lower bound.
Beta (β):
71
------------------------------------------------------------
------------------------------------------------------------
4) Example:
MAX
/ \
MIN MIN
/ \ / \
3 5 6 9
Step 1:
Evaluate left MIN node.
MIN(3,5) = 3
Step 2:
Move to right MIN node.
First child = 6
Update β:
β=6
Next child = 9
MIN(6,9) = 6
Step 3:
MAX chooses maximum:
MAX(3,6) = 6
So optimal value = 6.
------------------------------------------------------------
MAX
/ \
MIN MIN
/ \ / \
2 4 6 8
\
1
Step 1:
Left subtree:
MIN(2,4) = 2
Update α = 2
73
Step 2:
Right subtree:
First value = 6
β=6
Check:
α≥β?
2 ≥ 6 → No
Next value = 8
β = 6 still
Next value = 1
Now β = 1
Check:
α≥β?
2 ≥ 1 → TRUE
6) Alpha–Beta Algorithm:
2. If maximizingPlayer:
value = −∞
for each child:
value = max(value, ALPHABETA(child, depth−1, α, β, FALSE))
α = max(α, value)
if α ≥ β:
break (prune)
74
return value
3. If minimizingPlayer:
value = +∞
for each child:
value = min(value, ALPHABETA(child, depth−1, α, β, TRUE))
β = min(β, value)
if α ≥ β:
break (prune)
return value
------------------------------------------------------------
7) Time Complexity:
Worst Case:
O(b^d) (same as Minimax)
Best Case:
O(b^(d/2))
Where:
b = branching factor
d = depth of tree
------------------------------------------------------------
8) Advantages:
9) Disadvantages:
10) Applications:
Answer:
1) Introduction:
------------------------------------------------------------
2) Components of Block World:
1) Blocks
• Objects such as A, B, C, etc.
76
2) Table
• Surface on which blocks can be placed.
3) Robot Hand
• Used to pick up and move blocks.
4) States
• Different arrangements of blocks.
------------------------------------------------------------
3) Basic Rules of Block World:
4) State Representation:
Common predicates:
------------------------------------------------------------
5) Operators (Actions):
Typical actions in block world are:
1) PickUp(X)
Preconditions:
• Clear(X)
• OnTable(X)
77
• HandEmpty
Effects:
Add: Holding(X)
Delete: OnTable(X), Clear(X), HandEmpty
------------------------------------------------------------
2) PutDown(X)
Preconditions:
• Holding(X)
Effects:
Add: OnTable(X), Clear(X), HandEmpty
Delete: Holding(X)
------------------------------------------------------------
3) Stack(X, Y)
Preconditions:
• Holding(X)
• Clear(Y)
Effects:
Add: On(X,Y), Clear(X), HandEmpty
Delete: Holding(X), Clear(Y)
------------------------------------------------------------
4) Unstack(X, Y)
Preconditions:
• On(X,Y)
• Clear(X)
• HandEmpty
Effects:
Add: Holding(X), Clear(Y)
Delete: On(X,Y), Clear(X), HandEmpty
------------------------------------------------------------
78
6) Example:
Initial State:
On(A, Table)
On(B, Table)
On(C, A)
Clear(C)
Clear(B)
HandEmpty
Goal State:
On(A, B)
On(B, C)
Steps to solve:
1. Unstack(C, A)
2. PutDown(C)
3. PickUp(B)
4. Stack(B, C)
5. PickUp(A)
6. Stack(A, B)
Goal achieved.
------------------------------------------------------------
7) Applications:
• AI planning systems
• Robotics manipulation tasks
• Automated reasoning
• Teaching AI planning algorithms
------------------------------------------------------------
8) Advantages:
• Simplified environment.
• Not suitable for complex real-world problems.
------------------------------------------------------------
Conclusion:
Answer:
1) Introduction:
------------------------------------------------------------
2) Basic Idea:
In linear planning:
A strict sequence of actions is created.
Example:
A→B→C→D
In non-linear planning:
80
Example:
A must happen before C
B must happen before D
------------------------------------------------------------
3) Concept of Constraint Posting:
Types of constraints:
1) Ordering Constraints
Example:
Action A must occur before Action B.
------------------------------------------------------------
4) Components of Non-Linear Planning:
1) Initial State
Current state of environment.
2) Goal State
Desired conditions to be achieved.
3) Actions (Operators)
Each action has:
• Preconditions
• Effects (Add/Delete lists)
81
4) Partial Plan
Set of actions with constraints.
5) Constraints
Ordering and causal relations between actions.
------------------------------------------------------------
5) Working Procedure:
Step 1:
Start with an empty plan containing:
• Start node
• Finish node
Step 2:
Add goals to be satisfied.
Step 3:
Select a goal that is not satisfied.
Step 4:
Choose an action that can achieve the goal.
Step 5:
Add causal link and ordering constraint.
Step 6:
Resolve conflicts if any action threatens the causal link.
Step 7:
Repeat until all goals are satisfied.
------------------------------------------------------------
6) Example:
Goal:
Have tea ready.
82
Subgoals:
1. Boil water
2. Add tea leaves
3. Pour into cup
Constraints:
------------------------------------------------------------
7) Advantages:
• Flexible planning.
• Allows parallel execution of actions.
• Reduces unnecessary ordering constraints.
• Efficient for complex tasks.
------------------------------------------------------------
8) Disadvantages:
------------------------------------------------------------
9) Applications:
• Robotics planning
• Automated scheduling
• Workflow management
• Complex task planning
83
------------------------------------------------------------
Conclusion:
Answer:
1) Introduction:
------------------------------------------------------------
2) Basic Idea:
Sense → Act
Steps:
1. Sense the environment.
2. Interpret the current situation.
3. Perform an immediate action.
84
------------------------------------------------------------
------------------------------------------------------------
4) Architecture of Reactive Systems:
Typical structure includes:
1) Sensors
• Collect data from environment.
2) Controller
• Processes sensor data.
3) Actuators
• Perform actions based on decisions.
Structure:
------------------------------------------------------------
5) Behavior-Based System:
------------------------------------------------------------
6) Example:
Rules:
• If obstacle detected → turn.
• If dirt detected → clean area.
• If battery low → return to charging station.
------------------------------------------------------------
7) Advantages:
------------------------------------------------------------
8) Disadvantages:
• Limited intelligence.
• No long-term planning.
• Cannot handle complex reasoning tasks.
• Behavior may be unpredictable in complex situations.
------------------------------------------------------------
9) Applications:
• Autonomous robots
• Self-driving vehicles (basic control)
• Industrial automation
• Smart home systems
• Game AI
------------------------------------------------------------
10) Difference from Deliberative Systems:
86
Reactive Systems:
• Immediate response.
• No planning.
• Simple rules.
Deliberative Systems:
• Uses reasoning and planning.
• Maintains world model.
• Slower but more intelligent.
------------------------------------------------------------
Conclusion:
Answer:
Syntax:
[Element1, Element2, Element3, ...]
Example:
[1,2,3,4]
[a,b,c]
[apple,banana,orange]
Example:
[a, 5, x, [1,2]]
87
------------------------------------------------------------
Head
• First element of the list.
Tail
• Remaining elements of the list.
Example:
[a,b,c,d]
Head = a
Tail = [b,c,d]
Representation:
[Head | Tail]
Example:
[a,b,c] = [a | [b,c]]
------------------------------------------------------------
3) Empty List:
Syntax:
[]
Example:
[]
------------------------------------------------------------
88
1) Checking Membership
Example:
member(a, [a,b,c]).
Query:
?- member(b,[a,b,c]).
Output:
Yes
------------------------------------------------------------
Example:
Output:
X = [1,2,3,4]
------------------------------------------------------------
3) Length of List
Predicate: length(List, N)
Example:
length([a,b,c,d], N).
Output:
N=4
89
------------------------------------------------------------
add(X, L, [X|L]).
Example:
add(a, [b,c], X).
Output:
X = [a,b,c]
------------------------------------------------------------
2) Delete Element from List
Example:
?- delete(b, [a,b,c], X).
Output:
X = [a,c]
------------------------------------------------------------
3) Reverse a List
reverse([], []).
reverse([H|T], R) :-
reverse(T, RT),
append(RT, [H], R).
Example:
?- reverse([1,2,3], X).
Output:
90
X = [3,2,1]
------------------------------------------------------------
4) Find Last Element
last([X], X).
last([_|T], X) :-
last(T, X).
Example:
?- last([a,b,c,d], X).
Output:
X=d
------------------------------------------------------------
5) Check if List is Empty
empty([]).
Query:
?- empty([]).
Output:
Yes
-----------------------------------------------------------
6) Advantages of Lists in Prolog:
------------------------------------------------------------
Conclusion: