Problem Solving
Prof. Akila Victor
Agenda
• Definition
• Steps
• Components
• State Space
• Problem Approach
• Types of Problems
Definition
• According to psychology, “a problem-solving refers
to a state where we wish to reach to a definite goal
from a present state or condition.”
• According to computer science, a problem-solving is
a part of artificial intelligence which encompasses a
number of techniques such as algorithms, heuristics
to solve a problem.
• Therefore, a problem-solving agent is a goal-driven
agent and focuses on satisfying the goal.
Steps performed by Problem-solving agent
• Goal Formulation: This one is the first and simple step in
problem-solving. It organizes finite steps to formulate a
target/goals which require some action to achieve the goal.
Today the formulation of the goal is based on AI agents.
• Problem formulation: It is one of the core steps of problem-
solving which decides what action should be taken to achieve
the formulated goal. In AI this core part is dependent upon
software agent which consisted of the following components
to formulate the associated problem.
Components
• Initial State: This state requires an initial state for the
problem which starts the AI agent towards a specified
goal. In this state new methods also initialize problem
domain solving by a specific class.
• Action: This stage of problem formulation works with
function with a specific class taken from the initial state
and all possible actions done in this stage.
• Transition: This stage of problem formulation
integrates the actual action done by the previous action
stage and collects the final stage to forward it to their
next stage.
Cont…
• Goal test: This stage determines that the
specified goal achieved by the integrated
transition model or not, whenever the goal
achieves stop the action and forward into the next
stage to determines the cost to achieve the goal.
• Path costing: This component of problem-
solving numerical assigned what will be the cost
to achieve the goal. It requires all hardware
software and human working cost.
State Space
• Initial state, actions, and transition model together define
the state-space of the problem implicitly.
• State-space of a problem is a set of all states which can be
reached from the initial state followed by any sequence of
actions.
• The state-space forms a directed map or graph where nodes
are the states, links between the nodes are actions, and the path
is a sequence of states connected by the sequence of actions.
Cont…
• Search: It identifies all the best possible sequence
of actions to reach the goal state from the current
state. It takes a problem as an input and returns
solution as its output.
• Solution: It finds the best algorithm out of various
algorithms, which may be proven as the best
optimal solution.
• Execution: It executes the best optimal solution
from the searching algorithms to reach the goal
state from the current state.
Problem Approach
• 2 types
• Toy Problem: It is a concise and exact
description of the problem which is used by the
researchers to compare the performance of
algorithms.
• Real-world Problem: It is real-world based
problems which require solutions. Unlike a toy
problem, it does not depend on descriptions, but
we can have a general formulation of the problem.
Toy Problem
• 8 Puzzle Problem: Here, we have a 3×3 matrix with
movable tiles numbered from 1 to 8 with a blank
space. The tile adjacent to the blank space can slide
into that space.
Cont…
Cont…
• The problem formulation is as follows:
• States: It describes the location of each numbered tiles and the
blank tile.
• Initial State: We can start from any state as the initial state.
• Actions: Here, actions of the blank space is defined, i.e.,
either left, right, up or down
• Transition Model: It returns the resulting state as per the
given state and actions.
• Goal test: It identifies whether we have reached the correct
goal-state.
• Path cost: The path cost is the number of steps in the path
where the cost of each step is 1.
Cont…
• The aim of this problem is to place eight queens on a
chessboard in an order where no queen may attack
another. A queen can attack other queens
either diagonally or in same row and column.
Cont…
Cont…
• In the missionaries and cannibals problem, three
missionaries and three cannibals must cross a river
using a boat which can carry at most two people,
under the constraint that, for both banks, if there are
missionaries present on the bank, they cannot be
outnumbered by cannibals (if they were, the cannibals
would eat the missionaries). The boat cannot cross the
river by itself with no people on board. And, in some
variations, one of the cannibals has only one arm and
cannot row
Cont…
Real world Problems
• Towers of Hanoi.
• The Tower of Hanoi is a mathematical problem
formed of three towers. The purpose of the puzzle is
to push the whole stack to another bar. While
moving the stacks, we need to obey some simple
rules: we can only remove one disk at a time. We
can only transfer the top disc of one stack to another
bar which is empty. We cannot place the larger disc
on the smaller disc.
Travelling Salesman Problem
Consider the following
situation. You are given a
list of n cities with the
distance between any two
cities. Now, you have to
start with your office and to
visit all the cities only once
each and return to your
office. What is the shortest
path can you take? This
problem is called the
Traveling Salesman
Problem (TSP).
Cont…
• To make the problem simple, we consider 3-city-problem.
Let’s call the office ( A )and the 3 cities ( B ) ( C ) ( D )
respectively. We initialize the problem state by {A} means the
salesman departed from his office. As an operator, when he
visited city-B, the problem state is updated to {A, B}, where
the order of elements in { } is considered. When the salesman
visited all the cities, {A, B, C, D} in this case, the departed
point A is automatically added to the state which means {A, B,
C, D, A}. Therefore, the initial state of this TSP is {A} and the
final state(goal) is {A, X1, X2, X3, A} where traveled distance
is minimized.
Cont…
Water Jug
• Consider a scenario where you have a 3-liter jug and a 5-liter jug, and
you need to measure precisely 4 liters of water.
• Visualize the scenario by imagining the two jugs and a water source
to fill them.
• The challenge here is to determine a sequence of actions that will
allow you to reach the desired measurement of 4 liters, taking into
account the constraints and capacities of the jug.
• Constraint 1: The jugs have limited capacities.
• Constraint 2: You can only fill or pour water between the jugs or from
the source.
• Objective: The goal is to measure a specific quantity of water
accurately, typically by combining and transferring water between the
jugs.
Search Algorithms in AI
Cont…
• Uninformed search algorithms have no additional
information on the goal node other than the one
provided in the problem definition. The plans to reach
the goal state from the start state differ only by the
order and length of actions.
• Informed Search algorithms have information on the
goal state which helps in more efficient searching.
This information is obtained by a function that
estimates how close a state is to the goal state.
Cont…
Breadth First Search (BFS)
• Breadth-First Search algorithm is a graph traversing technique,
where you select a random initial node (source or root node) and
start traversing the graph layer-wise in such a way that all the
nodes and their respective children nodes are visited and explored.
• Breadth-first search implemented using FIFO queue data structure.
• A queue is an abstract data structure that follows the First-In-First-
Out methodology (data inserted first will be accessed first). It is
open on both ends, where one end is always used to insert data
(enqueue) and the other is used to remove data (dequeue).
Cont…
Cont…
Visiting a
node: Just like the
name suggests,
visiting a node
means to visit or
select a node.
Exploring a
node: Exploring
the adjacent nodes
(child nodes) of a
selected node.
Advantages& Disadvantages
Advantages
• BFS will provide a solution if any solution exists.
• If there are more than one solutions for a given problem, then
BFS will provide the minimal solution which requires the
least number of steps.
Disadvantages
• It requires lots of memory since each level of the tree must be
saved into memory to expand the next level.
• BFS needs lots of time if the solution is far away from the root
node.
Example
Solution
Depth First Search(DFS)
• The algorithm starts at the root (top) node of a tree and goes
as far as it can down a given branch (path), then backtracks
until it finds an unexplored path, and then explores it.
• The algorithm does this until the entire graph has been
explored.
• DFS uses a stack data structure to keep track of vertices.
Cont…
Example
Solve DFS
Examples
Cont…
Cont…
Cont…
Cont…
Cont…
Cont…
Cont…
Depth Limited Search
• Depth-limited search can solve the drawback of the
infinite path in the Depth-first search .
Depth-limited search can be terminated with
two Conditions of failure:
• Standard failure value: It indicates that problem does
not have any solution.
• Cutoff failure value: It defines no solution for the
problem within a given depth limit.
Cont…
Advantages
• Depth-limited search is Memory efficient.
Disadvantages
• Depth-limited search also has a disadvantage of
incompleteness.
• It may not be optimal if the problem has more than
one solution.
Example
Iterative Deepening
• There are two common ways to traverse a
graph, BFS and DFS. Considering a Tree (or Graph)
of huge height and width, both BFS and DFS are not
very efficient due to following reasons.
• BFS goes level by level, but requires more space.
Cont…
• IDDFS combines depth-first search’s space-
efficiency and breadth-first search’s fast search (for
nodes closer to root).
Example
Cont…
Advantages and Disadvantages
Advantages
• It combines the benefits of BFS and DFS search algorithm in
terms of fast search and memory efficiency.
Disadvantages
• The main drawback of IDDFS is that it repeats all the work of
the previous phase.
Bidirectional Search
• Heuristic refers to the concept of finding the shortest path from the current node in
the graph to the goal node.
• A heuristic, or a heuristic technique, is any approach to problem solving that uses
a practical method or various shortcuts in order to produce solutions that may not
be optimal but are sufficient given a limited timeframe or deadline
• The search always takes the shortest path to the goal node. This principle is used in
a bidirectional heuristic search.
• The only difference being the two simultaneous searches from the initial point and
from goal vertex.
• The main idea behind bidirectional searches is to reduce the time taken for search
drastically.
Cont…
Cont…
Advantages
• Bidirectional search is fast.
• Bidirectional search requires less memory
Disadvantages
• Implementation of the bidirectional search tree is
difficult.
• In bidirectional search, one should know the goal
state in advance.
Example
BFS VS Bidirectional
Informed Search
• The uninformed search algorithms which looked through search
space for all possible solutions of the problem without having
any additional knowledge about search space.
• But informed search algorithm contains an array of knowledge
such as how far we are from the goal, path cost, how to reach to
goal node, etc.
• This knowledge help agents to explore less to the search space
and find more efficiently the goal node.
• The informed search algorithm is more useful for large search
space.
• Informed search algorithm uses the idea of heuristic, so it is also
called Heuristic search.
Heuristics function
• Heuristic is a function which is used in Informed Search, and
it finds the most promising path.
• It takes the current state of the agent as its input and produces
the estimation of how close agent is from the goal.
• The heuristic method, however, might not always give the
best solution, but it guaranteed to find a good solution in
reasonable time.
• Heuristic function estimates how close a state is to the goal. It
is represented by h(n), and it calculates the cost of an optimal
path between the pair of states.
• The value of the heuristic function is always positive .
Algorithms
• Best First Search Algorithm(Greedy search)
• A* Search Algorithm
Best First Search
• A search method of selecting the best local choice at each step
in hopes of finding an optimal solution.
• Does not consider how optimal the current solution is.
• At each step, uses a heuristic to estimate the distance (cost) of
each local choice from the goal. •
• Steps: 1. Define a heuristic function h(x) to estimate the
distance to the goal from any state.
• 2. From the current state, determine the search space (actions)
for one step ahead.
• 3. Select the action from the search space that minimizes the
heuristic function.
Cont…
A* Algorithm
• A* Algorithm is one of the best and popular
techniques used for path finding and graph traversals.
• A lot of games and web-based maps use this
algorithm for finding the shortest path efficiently.
• It is essentially a best first search algorithm.
Cont…
• A* Algorithm extends the path that minimizes the
following function-
f(n) = g(n) + h(n)
Here,
• ‘n’ is the last node on the path
• g(n) is the cost of the path from start node to node ‘n’
• h(n) is a heuristic function that estimates cost of the
cheapest path from node ‘n’ to the goal node
Example
The numbers written on
edges represent the
distance between the
nodes.
The numbers written on
nodes represent the
heuristic value.
Find the most cost-
effective path to reach
from start state A to final
state J using A*
Algorithm.
Cont…
• A* Algorithm is one of the best path finding
algorithms.
• But it does not produce the shortest path always.
• This is because it heavily depends on heuristics.
Cont…
Advantages
• A* search algorithm is the best algorithm than other search
algorithms.
• A* search algorithm is optimal and complete.
• This algorithm can solve very complex problems.
Disadvantages
• It does not always produce the shortest path as it mostly based on
heuristics and approximation.
• A* search algorithm has some complexity issues.
• The main drawback of A* is memory requirement as it keeps all
generated nodes in the memory, so it is not practical for various
large-scale problems.
References
• https://www.tutorialandexample.com/problem-solving-in-artificial-i
ntelligence/
• https://www.geeksforgeeks.org/problem-solving-in-artificial-intellig
ence/
• https://www.researchgate.net/figure/A-solution-to-the-8-queens-pro
blem-presented-as-5-1-8-4-2-7-3-6_fig1_257549155
• https://towardsdatascience.com/basic-ai-algorithms-a7607b9ecdce
• https://www.youtube.com/watch?v=tZK3t-aUkKQ
• https://www.edureka.co/blog/breadth-first-search-algorithm/
• https://www.hackerearth.com/practice/algorithms/graphs/depth-first-
search/tutorial/
• https://www.programiz.com/dsa/graph-dfs
• https://www.interviewbit.com/tutorial/depth-first-search/
• https://iq.opengenus.org/bidirectional-search/