0% found this document useful (0 votes)
37 views

Lecture 7 10

Uploaded by

Pratham Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Lecture 7 10

Uploaded by

Pratham Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 101

Problem Solving Techniques

Ms. Anita Shrotriya


Assistant Professor-CSE
Manipal University Jaipur
Problem
• A problem is a task or situation that requires finding a solution
or making a decision.

• Problems can range from simple to complex, and AI aims to


develop algorithms and techniques that allow computers or
intelligent agents to solve these problems effectively.

• Problems can be diverse and come from various domains,


such as puzzle-solving, optimization, planning, decision-
making, and more.

• Examples of problems include finding the shortest path


between two locations on a map, solving a Sudoku puzzle,
scheduling tasks to minimize costs, playing a game, or
Problem Solving
• Problem solving is a process of generating solutions from
observed data.

• To solve the problem of building a system you should take the


following steps:
1. Define the problem accurately including detailed
specifications and what constitutes a suitable solution.
2. Scrutinize the problem carefully, for some features may
have a central affect on the chosen method of solution.
3. Segregate and represent the background knowledge
needed in the solution of the problem.
4. Choose the best solving techniques for the problem to solve
a solution.
Problem Space
• A formal description of the Problem.
• A problem space refers to the set of all possible states,
actions, and transitions that an intelligent agent can
encounter while trying to solve a specific problem.
• It represents the universe of possibilities that the agent
explores to find the best solution.
• The problem space is a conceptual framework that helps us
analyze and understand the structure of a problem and the
paths that can be taken to reach a solution.
• A Problem Space consists of:
• The current state of the world (initial state)
• A description of the actions we can take to transform one state of
the world into another (operators).
• A description of the desired state of the world (goal state), this
States
• A problem is defined by its elements and their relations.
• In each instant of the resolution of a problem, those elements
have specific descriptors (How to select them?) and relations.
• A state is a representation of those elements in a given
moment.
• Two special states are defined:
• Initial state (starting point)
• Final state (goal state)
State Modification : Successor Function
• A successor function is needed to move between different
states.
• A successor function is a description of possible actions, a set
of operators. It is a transformation function on a state
representation, which convert it into another state.
• The successor function defines a relation of accessibility
among states.
• Representation of the State
successorSpace
function:
• Conditions of applicability
• The state space is the set of all states reachable from the
• Transformation function
initial state.
• It forms a graph (or map) in which the nodes are states and
the arcs between nodes are actions.
• A path in the state space is a sequence of states connected by
Example: 8-puzzle
• State space: configuration of the eight tiles on the board
• Initial state: any configuration
• Goal state: tiles in a specific order
• Operators or actions: “blank moves”
• Condition: the move is within the board
• Transformation: blank moves Left, Right, Up, or Down
• Solution: optimal sequence of operators
Example: 8-puzzle

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.

• The characteristics of a problem guide the selection of


appropriate AI techniques and algorithms for solving it.
Problem Solving Techniques in AI
• Search Algorithms:
• Breadth-First Search (BFS): Explores neighboring states before
deeper levels of the search tree.
• Depth-First Search (DFS): Explores as far as possible along a branch
before backtracking.
• A* Search: Combines the advantages of BFS and heuristic-driven
search to find optimal paths.
• Iterative Deepening Search: Gradually increases the depth limit of
DFS to balance efficiency and optimality.
• Greedy Best-First Search: Selects the most promising state based on
a heuristic function.
• Heuristic Methods:
• Heuristic functions provide estimates of how close a state is to the
goal. They guide search algorithms by evaluating potential states.
• Hill Climbing: Moves toward the best neighboring state based on a
Search Strategies - Types
• Uninformed Search : strategies use only the information
(action) available in the problem definition.
• It does not use problem specific knowledge.
• Also called blind search
• All search strategies by the order in which nodes are-
expanded. Ex: Spril, zigzag…
Examples:
• Breadth-first search; Depth-first search; Depth-limited search;
Iterative deepening search; Beam Search
Search Strategies - Types
• Informed Search : search strategy that uses
problem-specific knowledge to find solutions more
efficiently. Also known as Heuristic Search.
• Strategies that known whether one goal state is “
more promising “ then another are called informed
search or Heuristic search

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.

• These problem-solving techniques are often tailored to


specific problem domains and scenarios.
• AI practitioners choose and adapt these techniques based on
the nature of the problem, available data, computational
resources, and desired outcomes.
• The evolution of AI continues to bring new techniques and
approaches, enabling more efficient and effective problem-
Some More Terms
• Solution : a sequence of actions that leads from the initial
state to a goal state.
• Optimal Solution : a solution that has the lowest path cost
among all solutions.
• Goal Test : way to determine whether a given state is a goal
state.
• Path Cost : numerical cost associated with a given path.
• Node : a data structure that keeps track of
• a state
• a parent (node that generated this node)
• an action (action applied to parent to get node)
• a path cost (from initial state to node)
Search Strategy
• Many (all?) AI problems can be formulated as search
problems!
• A search strategy is defined by picking the order of
node expansion.
• Strategies are evaluated along the following dimensions:
• completeness: does it always find a solution if one exists?
• time complexity: number of nodes generated
• space complexity: maximum number of nodes in memory
• optimality: does it always find a least-cost solution?
• systematicity: does it visit each state at most once?
• Time and space complexity are measured in terms of
• b:maximum branching factor of the search tree
• d: depth of the least-cost solution
• m: maximum depth of the state space (may be ∞)
The Concept of state Space

State space ={ “ all possible configuration” }


What exactly is “Searching for
solution”
• A solution is an action sequence: search algorithms work by
considering various action sequence.
• The possible action sequence , starting at the initial state form
a search tree with
 the initial state at the root
 The branches are the actions and
 The nodes corresponds to states in the state space of the
problem.
Leaf Node: n node with no children in the tree. The set of all
leaf nodes available for expansion at any given point is called
the frontier (is a set of all leaf node) ( bold in tree)
Infrastructure for Search
Algorithms
• Search algorithms require a data structure to keep
track of the search tree that is being constructed.
• Each node n of the tree contains four components:
 n.STATE: the state in the state space to which the
node corresponds;
 n.PARENT: the node in the search tree that
generated this node;
 n.ACTION: the action that was applied to the
parent to generate the node;
 n.PATH-COST: the cost of the path from the initial
state to the node,
Approach of Search

• Start with a frontier that contains the initial


state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier.
• If node contains goal state, return the
solution.
• Expand node, add resulting nodes to the
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

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…

• It can struct in infinite loop and never


make any progress. E
F
• What’s the solution???
Revised
•Approach
Start with a frontier that contains the initial state.
• Start with an empty explored set.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier.
• If node contains goal state, return the solution.
• Ad d the node to the explored set.
• Expand node, add resulting nodes to the frontier
if they aren't already in the frontier or the
explored set.
Now, How to decide which node has to be
remove?
The Frontier is a data structure, and it totally
depends upon which data structure we use.

One of the simplest data structure for adding or


removing a node is :

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 :

Depth First Search


search algorithm that always
expands the deepest node in the
frontier
Depth First Search
• Depth First Search (DFS) is a fundamental graph traversal
algorithm used to explore and analyze graphs or trees in
computer science and graph theory.
• It systematically visits all the vertices (nodes) and edges of a
graph in a specific manner, focusing on exploring as deeply as
possible before backtracking.
• Here's a step-by-step explanation of the Depth First Search
algorithm:
1. Choose a starting vertex: Begin by selecting a vertex as the starting
point for the traversal.
2. Mark the vertex as visited: When you visit a vertex, mark it as visited
to keep track of the nodes you have already explored.
3. Explore adjacent vertices: From the current vertex, choose an adjacent
vertex that hasn't been visited yet. Move to this adjacent vertex and
Depth First Search
• Maintain stack of nodes to visit.
• Evaluation of DFS
• Complete? : the depth of a search can be infinite.
B’coz,
No

• Time Complexity? : m)case, It is equal to the search tree siz


In worst
O(b

• 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 :

Breadth First Search


search algorithm that always
expands the shallowest node in the
frontier
Breadth First Search
• It is another fundamental graph traversal algorithm used to explore
and analyze graphs or trees in computer science and graph theory.
BFS systematically visits all the vertices and edges of a graph by
exploring vertices level by level, starting from a designated source
vertex (or starting node).
• This algorithm is particularly useful for finding the shortest path in
unweighted graphs, as it guarantees that the shortest path from the
source to any other reachable vertex is found first.
• Here's a step-by-step explanation of the Breadth First Search
algorithm:
1. Choose a starting vertex: Begin by selecting a vertex as the starting
point for the traversal.
2. Mark the vertex as visited: When you visit a vertex, mark it as visited to
keep track of the nodes you have already explored.
3. Explore adjacent vertices at the current level: From the current vertex,
Breadth First Search
• Maintain queue of nodes to visit.
• Evaluation of BFS
• Complete? :
B’coz,
Yes the depth of a search is finite.

• Time Complexity? : case,


In any
O(bd
) It is equal to the solution length o

• 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.

Can be implemented using recursion or an


explicit stack.
Data Recursive approach is elegant but can lead to
Implemented using a queue.
Structure stack overflow for deep graphs.
Stack is used to keep track of nodes to be
explored.
Recursive DFS can use less memory compared to
Requires more memory due to queue storage.
Memory BFS.
It stores all nodes at the current level before
Usage Stack usage in DFS may be more memory-
moving to the next level.
efficient for deep graphs.

May not visit all nodes in disconnected graphs


Completene Guarantees visiting all reachable nodes in the
unless applied multiple times from different
ss graph.
starting nodes.

DFS does not guarantee finding the shortest path


Shortest between nodes. Guarantees finding the shortest path in
Path It may find longer paths before finding shorter unweighted graphs.
ones.

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 ???

• add guidance (“heuristic estimate”)


• “informed search”
“Thank you for
being such an
engaged
audience during
my
presentation.”
- Anita Shrotriya

You might also like