3-Module2 - Introduction to Problem Solving by searching methods-30-07-2024
3-Module2 - Introduction to Problem Solving by searching methods-30-07-2024
• 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.
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
• 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
6
Find the route from S to G using BFS.