Lecture 7 10
Lecture 7 10
The 8-
puzzle
search
space
consists
of 8!
states
(40320)
Example: n queens
• State space: configurations from 0 to n queens on the board
with only one queen per row and column
• Initial state: configuration without queens on the board
• Goal state: configuration with n queens such that no queen
attacks any other
• Operators or actions: place a queen on the board
• Condition: the new queen is not attacked by any other already
placed
• Transformation: place a new queen in a particular square of the
board
• Solution: one solution (cost is not considered)
• Homework:
Example: 5 queens
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Characteristics of a Problem
1.Well-Defined Goal: A problem should have a clear and well-
defined goal or objective that the AI system aims to achieve.
The goal provides a target for the solution-seeking process.
2.Initial State: The problem typically starts from a specific
initial state or condition. This initial state represents the
starting point from which the AI system begins its search or
reasoning process.
3.Set of Actions: Problems involve a set of possible actions
that can be taken by the AI system to move from one state to
another. These actions represent the decisions or steps that
the system can make to progress toward the goal.
4.Transition Model: The transition model specifies how the
state changes when an action is taken. It defines the
relationship between different states and the actions that
Characteristics of a Problem
7.Optimality Criteria: Problems often have criteria for
determining the optimality of a solution. These criteria can be
related to minimizing or maximizing certain factors, such as
cost, time, distance, or utility.
8.Search Space: The set of all possible states and actions that
can be explored to reach a solution is known as the search
space. The size and structure of the search space influence the
complexity of the problem-solving process.
9.Complexity: The complexity of a problem can be measured in
terms of factors like the size of the search space, the number of
possible actions, and the difficulty of finding a solution.
Complex problems may require advanced AI techniques to solve
effectively.
10.Uncertainty: Some problems involve uncertainty or
Characteristics of a Problem
12.Interactions and Dependencies: Problems may involve
interactions and dependencies between different
components or variables. Understanding these interactions is
crucial for accurate decision-making.
13.Dynamic Nature: Certain problems involve dynamic
environments where conditions change over time. The AI
system needs to adapt to these changes to maintain
effectiveness.
14.Scalability: Scalability refers to the ability of the problem-
solving approach to handle larger or more complex instances
of the problem.
Examples:
• Generate and Test search; Hill Climbing; Best-first
search; Greedy best-first search; A* search; Depth
first branch & bound search; Simulated Annealing
Problem Solving Techniques in AI
• Constraint Satisfaction Problems (CSPs):
• CSPs involve finding solutions that satisfy a set of constraints.
• Backtracking: Systematically explores possible solutions,
backtracking when constraints are violated.
• Constraint Propagation: Infers constraints from the relationships
between variables.
• Adversarial Search and Game Playing:
• Minimax Algorithm: Used in two-player games to find optimal
strategies by considering the opponent's moves.
• Alpha-Beta Pruning: Optimizes the minimax algorithm by
eliminating branches that are guaranteed to lead to worse
outcomes.
• Planning Algorithms:
• Generate sequences of actions to achieve a goal within a given set
of constraints.
Problem Solving Techniques in AI
• Reinforcement Learning:
• Agents learn to take actions to maximize cumulative rewards in an
environment.
• Q-Learning: Learns an action-value function that guides decision-
making based on expected future rewards.
• Deep Q Networks (DQN): Combines Q-learning with deep neural
networks for more complex problems.
• Expert Systems:
• Utilize human expertise and knowledge to solve complex problems
in specific domains.
• Rule-Based Systems: Represent knowledge as a set of IF-THEN rules
to make inferences.
• Optimization Algorithms:
• Solve optimization problems by finding the best possible solution
within a given set of constraints.
Problem Solving Techniques in AI
• Fuzzy Logic:
• Handles uncertainty and imprecision by allowing degrees of truth
between true and false.
• Neural Networks and Deep Learning:
• Neural networks are used for pattern recognition, function
approximation, and decision-making.
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Fronti
er
A
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Fronti
er
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Frontie
r
B
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Fronti
er
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Fronti
er
C D
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Frontier
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Fronti
er
E D
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Frontier
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
Find a path from A to A
E. B
Frontier
C D
• Start with a frontier that contains the initial
state.
• Repeat:
• If the frontier is empty, then no solution.
E
• Remove a node from the frontier. F
• If node contains goal state, return the
solution.
What could go
wrong?
Find a path from A to A
E. B
Fronti
er
C D
E
F
Find a path from A to A
E. B
Frontie
r
A
C D
E
F
Find a path from A to A
E. B
Fronti
er
C D
E
F
Find a path from A to A
E. B
Frontie
r
B
C D
E
F
Find a path from A to A
E. B
Fronti
er
C D
E
F
Find a path from A to A
E. B
Frontier
A C
D
C D
E
F
Find a path from A to A
E. B
Frontier
D C D
• A B A B…
stac
last-in fik
rst-out data
type
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
E
F
Find a path from A to A
E. B
Frontie
r
A
C D
Explored
Set
E
F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
A
E
F
Find a path from A to A
E. B
Frontie
r
B
C D
Explored
Set
A
E
F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
A
E
B F
Find a path from A to A
E. B
Fronti
er
C D
C D
Explored
Set
A
E
B F
Find a path from A to A
E. B
Frontie
r
C
C D
Explored
Set
D
A
E
B F
Find a path from A to A
E. B
Fronti
er
C F
C D
Explored
Set
D
A
E
B F
Find a path from A to A
E. B
Frontie
r
C
C D
Explored
Set
D F
A
E
B F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
D F C
A
E
B F
Find a path from A to A
E. B
Frontie
r
E
C D
Explored
Set
D F C
A
E
B F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
D F C
A
E
B F
This is known as :
• Space Complexity?O(bm)
: In worst case, Maximum
Length of the tree (m) and
no. of children for each node
(b)
Let’s use another simple data structure for
adding or removing a node :
queue
fi rst-in fi rst-out data
type
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
E
F
Find a path from A to A
E. B
Frontie
r
A
C D
Explored
Set
E
F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
A
E
F
Find a path from A to A
E. B
Frontie
r
B
C D
Explored
Set
A
E
F
Find a path from A to A
E. B
Fronti
er
C D
Explored
Set
A
E
B F
Find a path from A to A
E. B
Fronti
er
C D
C D
Explored
Set
A
E
B F
Find a path from A to A
E. B
Frontier
C D
Explored
Set
C
A
E
B F
Find a path from A to A
E. B
Fronti
er
D E
C D
Explored
Set
C
A
E
B F
Find a path from A to A
E. B
Frontier
C D
Explored
Set
C D
A
E
B F
Find a path from A to A
E. B
Fronti
er
E F
C D
Explored
Set
C D
A
E
B F
Find a path from A to A
E. B
Fronti
er
F
C D
Explored
Set
C D
A
E
B F
This is known as :
• Space Complexity?O(b
: d) In any case, we must maintain
the full frontier. Length till the
• Optimal? : Yes solution (d) is
If step cost and no. for
equal of children
all or for
each node (b)
ONE (1).
• Let’s See both strategies in visual representation.
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Depth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Breadth-First
Search
A
Aspect Depth First Search (DFS) Breadth First Search (BFS)
Traversal Explores as deeply as possible along each branch Explores all neighbors before moving to the
Order before backtracking. next level.
Used in topological sorting, finding connected Suitable for shortest path finding, analyzing
Applications
The Problem
• All these uninformed methods / strategies are slow (Because
all are blind).
• Solution ???