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

3-Module2 - Introduction to Problem Solving by searching methods-30-07-2024

The document discusses uninformed search techniques in problem-solving, detailing concepts such as search trees, search strategies, and the implementation of algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). It outlines the properties, advantages, and disadvantages of these algorithms, emphasizing their completeness, time and space complexity, and optimality. Additionally, it introduces depth-limited and bidirectional search methods, highlighting their unique characteristics and challenges.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

3-Module2 - Introduction to Problem Solving by searching methods-30-07-2024

The document discusses uninformed search techniques in problem-solving, detailing concepts such as search trees, search strategies, and the implementation of algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS). It outlines the properties, advantages, and disadvantages of these algorithms, emphasizing their completeness, time and space complexity, and optimality. Additionally, it introduces depth-limited and bidirectional search methods, highlighting their unique characteristics and challenges.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 78

Searching for Solutions-

uninformed search techniques


INTRODUCTION
• Problem can described by
» Initial state
» Operator or successor function
» State space
» Path
» Goal test
Searching for Solutions
• Search Tree

• Search Graph
Tree search example
Tree search example
Tree search example
Tree search algorithms
• Basic idea:
Search node – Expanding - Generating
Representation of nodes
• STATE: the state in the state space to which the node
corresponds;
• PARENT: the node in the search tree that generated
this node;
• ACTION: the action that was applied to the parent to
generate the node;
• PATH-COST: the cost, traditionally denoted by g(n), of
the path from the initial state to the node, as
indicated by the parent pointers.
Implementation: general tree
search
Key concepts in search
• Suppose choose Sibiu first.
– Check to see whether it is a goal state (it is not) and then expand
it to get In(Arad), In(Fagaras), In(Oradea), and In(RimnicuVilcea).
– Then choose any of these four or go back and choose Timisoara
or Zerind.
• Each of these six nodes is a leaf node, a node with no children in
the tree.
• Set of all leaf nodes available for expansion at any given point is
called the frontier.
• Process of expanding nodes on the frontier continues until either a
solution is found or there are no more states to expand.
• Search algorithm vary primarily according to how they choose
which state to expand next— so-called search strategy.
• In(Arad) is a repeated state in the search tree, generated in this case
by a loopy path - Special case of redundant paths
Search strategies
• 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?
• 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 ∞)
Infrastructure for search algorithms
• Frontier needs to be stored - the search algorithm can easily choose the
next node to expand according to its preferred strategy.
• Appropriate data structure for this is a queue.
• Operations on a queue are as follows:
– EMPTY?(queue) returns true only if there are no more elements in the
queue.
– POP(queue) removes the first element of the queue and returns it.
– INSERT(element, queue) inserts an element and returns the resulting
queue.
• Queues are characterized by the order of stored nodes.
• Common variants are
– FIFO QUEUE or FIFO queue, which pops the oldest element of the
queue;
– LIFO QUEUE the last-in, first-out or LIFO queue (stack); and
– the priority queue, pops the element of the queue with the highest
priority
• Explored set can be implemented using hash table to allow efficient
checking for repeated states.
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.
Breadth-first
search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at
end
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at
end
EDC
Breadth-first search

• Expand shallowest unexpanded node


• Implementation:
– fringe is a FIFO queue, i.e., new successors go at
end
GFED
Breadth-first search

• Expand shallowest unexpanded node


• Implementation:
– fringe is a FIFO queue, i.e., new successors go at
end
GFED
Example
Solution
Properties of breadth-first
search

• Complete? Yes (if b is finite)

• Time? 1+b+b2+b3+… +bd + b(bd-1) = O(bd)

• Space? O(bd) (keeps every node in memory)

• Optimal? Yes (if cost = 1 per step)

• Space is the bigger problem (more than time)


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.
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
DFS
Properties of depth-first
search
• Complete? No: fails in infinite-depth spaces, spaces with loops
• Modify to avoid repeated states along path

–  complete in finite spaces

• Time? O(bm): terrible if m is much larger than d


– but if solutions are dense, may be much faster than breadth-first

• Space? O(bm), i.e., linear space!

• Optimal? No
BFS
DFS
Depth-limited search
Similar to depth-first search with a depth limit l,
i.e., nodes at depth l have no successors
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.
Example
Depth Limited Search
• Recursive implementation:
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.
Bi-directional search

• Alternate searching from the start state toward the goal


and from the goal state toward the start.
• Stop when the frontiers intersect.
• Works well only when there are unique start and goal
states.
• Requires the ability to generate “predecessor” states.
• Can (sometimes) lead to finding a solution more quickly.
• Time complexity: O(bd/2). Space complexity: O(bd/2).
WHY BDS
Time and space complexity
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
Summary of algorithms
Find the route from S to G using BFS.

6
Find the route from S to G using BFS.

You might also like