SlideShare a Scribd company logo
1 of 34
Download to read offline
CHAPTER - 2


      Problem Spaces and
      P roblem Solving by
           Searching
                  Presented By :
                  Radhika Srinivasan PG
                  Roll No : 45
What we will learn today …




 What is Problem Spaces?
 How to Search to get solutions?
 Using Different searching algorithms i.e.
  basically used in AI
 Some Toy problems and Real world problems
Introduction


     Now, we’ll study about what are the kinds of problems
    where the AI is concerned and the technique that is
    used to solve those problems.
       There are 4 things concerned to solve a particular
    problem.
   Define the problem precisely.
   Analyze the problem.
   Isolate and represent the task knowledge i.e. required
    to solve the problem.
   Finally, choose the best problem solving technique and
    apply to the particular problem.
Areas


  Problem Solving
-Puzzles
-Play games, e.g chess
-Symbolic integration of mathematical formulas.
-Some programs can improve their performance with
   experience
 Logical reasoning

– Prove assertions (theorems) by manipulating a database
   of facts
Areas


  Language
– Understanding of natural language
– Translation
– E.g. Spelling checker
 Programming

– Write computer programs based on a description
 Systems and languages

– Time-sharing, list processing, and interactive debugging
   were developed in the AI research
What is problem space ?


 Problem space is a set of states and the connections
  between to represent the problem. Problem space graph
  is used to represent a problem space. In the graph, the
  states are represented by nodes of the graph, and the
  operators by edges between nodes.
 For simplicity they are often represented as trees,
  where the initial state is the root of the tree. The cost of
  the simplification is that any state that can be reached
  by two different paths will be represented by duplicate
  nodes thereby increasing the tree size. The benefit of
  using tree is that the absence of cycles greatly
  simplifies many search algorithms.
Search


  State Space and Problem Reduction
– State space
 An operator produces exactly one new state

– Problem reduction
 An operator produces a set of sub problems, each of
   which have to be solved.
- E.g.
       Tower of Hanoi
Search - problem representation


 State space graph
 It is represented like nodes and edges where initial
  state to the goal state. It can also represent as tree
  graph.
Search Strategy


   A strategy is defined by picking the order of node
    expansion. Strategy is evaluated among the following
    dimensions.
   Completeness- does it always find a solution if one
    exists?
   Time complexity- no. of nodes generated.
   Space complexity- max no. of nodes in memory.
   Optimality- does it always find least cost solution?
   Time and space is measured in ‘b’ – max branching
    factor of search tree. ‘d’- depth of least cost solution.
    ‘m’ – max depth of the state space may be (infinite)
Which are the Search Types ?


  Blind search algorithms are as follows:
 In blind search the number of nodes can be

   extremely large, The order of expanding the nodes is
   arbitrary
  - Breadth First Search
  - Depth First Search
 Heuristic search

  - Ordered Search
  - A* An optimal search
 Consider State space graph as general graph i.e. nodes
   and points. Graphs can be directed undirected or mixed
   graph.
Breadth-First Search


 Breadth First Search (BFS) searches breadth-wise in
  the problem space. Breadth-First search is like
  traversing a tree where each node is a state which may
  a be a potential candidate for solution.
 Breadth first search expands nodes from the root of the
  tree and then generates one level of the tree at a time
  until a solution is found. It is very easily implemented
  by maintaining a queue of nodes.
 Initially the queue contains just the root. In each
  iteration, node at the head of the queue is removed and
  then expanded. The generated child nodes are then
  added to the tail of the queue.
ALGORITHM: BREADTH-FIRST SEARCH



 Create a variable called NODE-LIST and set it to the
  initial state.
 Loop until the goal state is found or NODE-LIST is
  empty.
   • Remove the first element, say E, from the NODE-
      LIST. If NODE-LIST was empty then quit.
   • For each way that each rule can match the state
      described in E do:
 - Apply the rule to generate a new state.
  - If the new state is the goal state, quit and return this
  state.
  - Otherwise add this state to the end of NODE-LIST
Advantages : BFS




 Breadth first search will never get trapped exploring the
  useless path forever.
 If there is a solution, BFS will definitely find it out.
 If there is more than one solution then BFS can find the
  minimal one that requires less number of steps.
Disadvantages :BFS


 The main drawback of Breadth first search is its
  memory requirement. Since each level of the tree must
  be saved in order to generate the next level, and the
  amount of memory is proportional to the number of
  nodes stored, the space complexity of BFS is O(bd).
 As a result, BFS is severely space-bound in practice so
  will exhaust the memory available on typical computers
  in a matter of minutes.
 If the solution is farther away from the root, breath first
  search will consume lot of time.
DEPTH FIRST SEARCH



 Depth First Search (DFS) searches deeper into the
  problem space.
 BFS always generates successor of the deepest
  unexpanded node.
 Depth First Search uses last-in first-out stack for
  keeping the unexpanded nodes.
 More commonly, depth-first search is implemented
  recursively, with the recursion stack taking the place of
  an explicit node stack.
ALGORITHM: DEPTH FIRST SEARCH


 If the initial state is a goal state, quit and return
  success.
 Otherwise, loop until success or failure is signalled.
  a) Generate a state, say E, and let it be the successor
  of the initial state. If there is no successor, signal
  failure.
  b) Call Depth-First Search with E as the initial state.
  c) If success is returned, signal success. Otherwise
  continue in this loop.
ADVANTAGES


 The advantage of depth-first Search is that memory
  requirement is only linear with respect to the search
  graph.
 The time complexity of a depth-first Search to depth d
  is O(b^d) since it generates the same set of nodes
  as BFS.
 If depth-first search finds solution without exploring
  much in a path then the time and space it takes will be
  very less.
DISADVANTAGES


 There is a possibility that it may go down the left-most
  path forever. Even a finite graph can generate an
  infinite tree.
 Depth-First Search is not guaranteed to find the
  solution.
 And there is no guarantee to find a minimal solution, if
  more than one solution exists.
Bidirectional Search


  The algorithms so far use forward reasoning, i.e.
   moving from the start node towards a goal node. some
   cases we could use backward reasoning, i.e. moving
   from the goal state to the start state.
 Forward and backward reasoning can be combined into
   a technique called bidirectional search.
  - One starting from the initial state and searching
   forward
 - One starting from the goal state and searching
   backward The search terminates when the two graphs
   intersect
Problems in Real World


   There are some toy searching that we’ll see
    this technique are used to solve some real world
    problems like:
   Route finding.(computer networks, airline travel
    planning system)
   Layout problems (VLSI layout, furniture layout,
    packaging)
   Assembly sequencing.(Assembly of electrical motors)
   Task Scheduling.(Time tables, manufacturing)
Water Jug Problem


 Consider the following problem:
          A Water Jug Problem: You are given two jugs, a
  4-gallon one and a 3-gallon one, a pump which has
  unlimited water which you can use to fill the jug, and
  the ground on which water may be poured. Neither jug
  has any measuring markings on it. How can you get
  exactly 2 gallons of water in the 4-gallon jug?
 State Representation and Initial State –

       We will represent a state of the problem as a tuple
  (x, y) where x represents the amount of water in the 4-
  gallon jug and y represents the amount of water in the
  3-gallon jug. Goal state as (2,y).
Production Rules


   (x,y)If x<4 -> (4,y)
   (x,y)If y<3 ->(x,3)
   (x,y)If x>0 ->(x-d,y)
   (x,y)If y>0 ->(x,y-d)
   (x,y)If x>0 ->(0,y)
   (x,y)If y>0 ->(x,0)
   (x,y)If(x+y>=4 and y>0) ->(4,y-(4-x))
   (x,y)If (x+y>=3 and x>0) ->(x-(3-y),3)
   (x,y)If(x+y<=4 and y>0) ->(x+y,0)
   (x,y)If (x+y<=3 and x>0) ->(0,x+y)
   (0,2)->(2,0)
Solution


               4 Gallon Jug   3 Gallon Jug

                     0             0          pump
                     4             0

                     1             3

                     1             0
4 Gallon jug         0             1         3 Gallon jug
                     4             1

                     2             3
Search Tree : Water Jug Problem



                        (0,0)


        (4,0)                           (0,3)



(4,3)   (0,0)   (1,3)           (4,3)   (0,0)   (3,0)
8 Puzzle Problem




   1    3        5   1   2        3

   2    7        4   4   5        6

   6             8   7   8



   Start State       Goal State
8 Puzzle Problem


  State space (S)
  Location of each of the 8 tiles(and the blank tile)
 Start State (s)

  Starting configuration
 Operators(O)

   Four Operators : Right, Left, Up, Down
 Goals(G)

   one of the goal configuration
8 Queen Problem


  Problem: Place 8 queens on a chess board so that none
   of them attack each other
 Formulation- I

 - A state is an arrangement of 0 to 8 queens on the
   board
 - Operators add a queen to any square.
 This formulation is not a systematic way to find the
   solution, it takes a long time to get the solution.
8 Queen Problem


    Formulation – II
    - A state is an arrangement of 0-8 queen with no one
     attacked.
    - Operators place a queen in the left most empty
     column.
    - More systematic than formulation-I
8 Queen Problem


    Formulation –III
     - A state is an arrangement of 8 queens on in each
     column.
    -Operators move an attacked queen to another square
     in the same column.
    -Keep on shuffling the queen until the goal is reached.
    - This formulation is more systematic hence , it is also
     called as Iterative Formulation.
8 Queen Problem : Solution
Missionaries and Cannibals


   Three missionaries and three cannibals find themselves
    on a side of river. They agreed to get to the other side
    of river. But missionaries are afraid of being eaten by
    cannibals so, the missionaries want to manage the trip
    in such a way that no. of missionaries on either side of
    the river is never less than the no. of cannibals on the
    same side. The boat is able to hold only 2 people at a
    time.
Missionaries and Cannibals


   State(#m,#c,1/0)
    #m – number of missionaries on first bank
    #c – number of cannibals on first bank

 The last bit indicate whether the boat is in the first
  bank.
 Operators

   • Boat carries (1,0) or (0,1) or (1,1) or (2,0) or (0,2)
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai

More Related Content

What's hot

Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6Kirti Verma
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programmingTafhim Islam
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logicAmey Kerkar
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
4 informed-search
4 informed-search4 informed-search
4 informed-searchMhd Sb
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
Automata presentation turing machine programming techniques
Automata presentation turing machine programming techniquesAutomata presentation turing machine programming techniques
Automata presentation turing machine programming techniquesBasit Hussain
 
Lecture 26 local beam search
Lecture 26 local beam searchLecture 26 local beam search
Lecture 26 local beam searchHema Kashyap
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithmMegha Sharma
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAsst.prof M.Gokilavani
 

What's hot (20)

Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
 
AI: AI & Problem Solving
AI: AI & Problem SolvingAI: AI & Problem Solving
AI: AI & Problem Solving
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
First order logic
First order logicFirst order logic
First order logic
 
Knowledge representation and Predicate logic
Knowledge representation and Predicate logicKnowledge representation and Predicate logic
Knowledge representation and Predicate logic
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
5 csp
5 csp5 csp
5 csp
 
4 informed-search
4 informed-search4 informed-search
4 informed-search
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Automata presentation turing machine programming techniques
Automata presentation turing machine programming techniquesAutomata presentation turing machine programming techniques
Automata presentation turing machine programming techniques
 
Lecture 26 local beam search
Lecture 26 local beam searchLecture 26 local beam search
Lecture 26 local beam search
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Local search algorithm
Local search algorithmLocal search algorithm
Local search algorithm
 
Problems, Problem spaces and Search
Problems, Problem spaces and SearchProblems, Problem spaces and Search
Problems, Problem spaces and Search
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 

Viewers also liked

State Space Search(2)
State Space Search(2)State Space Search(2)
State Space Search(2)luzenith_g
 
Problems problem spaces and search
Problems problem spaces and searchProblems problem spaces and search
Problems problem spaces and searchAmey Kerkar
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & ReasoningSajid Marwat
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logicgiki67
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representationSravanthi Emani
 

Viewers also liked (7)

State space search
State space search State space search
State space search
 
State Space Search(2)
State Space Search(2)State Space Search(2)
State Space Search(2)
 
Problems problem spaces and search
Problems problem spaces and searchProblems problem spaces and search
Problems problem spaces and search
 
Knowledge Representation & Reasoning
Knowledge Representation & ReasoningKnowledge Representation & Reasoning
Knowledge Representation & Reasoning
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logic
 
Frames
FramesFrames
Frames
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representation
 

Similar to (Radhika) presentation on chapter 2 ai

problem solve and resolving in ai domain , probloms
problem solve and resolving in ai domain , problomsproblem solve and resolving in ai domain , probloms
problem solve and resolving in ai domain , problomsSlimAmiri
 
Artificial intelligent Lec 3-ai chapter3-search
Artificial intelligent Lec 3-ai chapter3-searchArtificial intelligent Lec 3-ai chapter3-search
Artificial intelligent Lec 3-ai chapter3-searchTaymoor Nazmy
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptxGavy11
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial IntelligenceJay Nagar
 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxRatnakar Mikkili
 
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearch
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearchJarrar.lecture notes.aai.2011s.ch3.uniformedsearch
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearchPalGov
 
SP14 CS188 Lecture 2 -- Uninformed Search.pptx
SP14 CS188 Lecture 2 -- Uninformed Search.pptxSP14 CS188 Lecture 2 -- Uninformed Search.pptx
SP14 CS188 Lecture 2 -- Uninformed Search.pptxAnimeGuru1
 
Amit ppt
Amit pptAmit ppt
Amit pptamitp26
 
CptS 440 / 540 Artificial Intelligence
CptS 440 / 540 Artificial IntelligenceCptS 440 / 540 Artificial Intelligence
CptS 440 / 540 Artificial Intelligencebutest
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and SearchHitesh Mohapatra
 
AI_03_Solving Problems by Searching.pptx
AI_03_Solving Problems by Searching.pptxAI_03_Solving Problems by Searching.pptx
AI_03_Solving Problems by Searching.pptxYousef Aburawi
 

Similar to (Radhika) presentation on chapter 2 ai (20)

problem solve and resolving in ai domain , probloms
problem solve and resolving in ai domain , problomsproblem solve and resolving in ai domain , probloms
problem solve and resolving in ai domain , probloms
 
Artificial intelligent Lec 3-ai chapter3-search
Artificial intelligent Lec 3-ai chapter3-searchArtificial intelligent Lec 3-ai chapter3-search
Artificial intelligent Lec 3-ai chapter3-search
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Artificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptxArtificial Intelligence_Searching.pptx
Artificial Intelligence_Searching.pptx
 
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearch
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearchJarrar.lecture notes.aai.2011s.ch3.uniformedsearch
Jarrar.lecture notes.aai.2011s.ch3.uniformedsearch
 
SP14 CS188 Lecture 2 -- Uninformed Search.pptx
SP14 CS188 Lecture 2 -- Uninformed Search.pptxSP14 CS188 Lecture 2 -- Uninformed Search.pptx
SP14 CS188 Lecture 2 -- Uninformed Search.pptx
 
Amit ppt
Amit pptAmit ppt
Amit ppt
 
Problem space
Problem spaceProblem space
Problem space
 
Problem space
Problem spaceProblem space
Problem space
 
Problem space
Problem spaceProblem space
Problem space
 
l2.pptx
l2.pptxl2.pptx
l2.pptx
 
l2.pptx
l2.pptxl2.pptx
l2.pptx
 
CptS 440 / 540 Artificial Intelligence
CptS 440 / 540 Artificial IntelligenceCptS 440 / 540 Artificial Intelligence
CptS 440 / 540 Artificial Intelligence
 
CS767_Lecture_02.pptx
CS767_Lecture_02.pptxCS767_Lecture_02.pptx
CS767_Lecture_02.pptx
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
AI Lesson 04
AI Lesson 04AI Lesson 04
AI Lesson 04
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
 
AI_03_Solving Problems by Searching.pptx
AI_03_Solving Problems by Searching.pptxAI_03_Solving Problems by Searching.pptx
AI_03_Solving Problems by Searching.pptx
 

(Radhika) presentation on chapter 2 ai

  • 1. CHAPTER - 2 Problem Spaces and P roblem Solving by Searching Presented By : Radhika Srinivasan PG Roll No : 45
  • 2. What we will learn today …  What is Problem Spaces?  How to Search to get solutions?  Using Different searching algorithms i.e. basically used in AI  Some Toy problems and Real world problems
  • 3. Introduction Now, we’ll study about what are the kinds of problems where the AI is concerned and the technique that is used to solve those problems. There are 4 things concerned to solve a particular problem.  Define the problem precisely.  Analyze the problem.  Isolate and represent the task knowledge i.e. required to solve the problem.  Finally, choose the best problem solving technique and apply to the particular problem.
  • 4. Areas  Problem Solving -Puzzles -Play games, e.g chess -Symbolic integration of mathematical formulas. -Some programs can improve their performance with experience  Logical reasoning – Prove assertions (theorems) by manipulating a database of facts
  • 5. Areas  Language – Understanding of natural language – Translation – E.g. Spelling checker  Programming – Write computer programs based on a description  Systems and languages – Time-sharing, list processing, and interactive debugging were developed in the AI research
  • 6. What is problem space ?  Problem space is a set of states and the connections between to represent the problem. Problem space graph is used to represent a problem space. In the graph, the states are represented by nodes of the graph, and the operators by edges between nodes.  For simplicity they are often represented as trees, where the initial state is the root of the tree. The cost of the simplification is that any state that can be reached by two different paths will be represented by duplicate nodes thereby increasing the tree size. The benefit of using tree is that the absence of cycles greatly simplifies many search algorithms.
  • 7. Search  State Space and Problem Reduction – State space  An operator produces exactly one new state – Problem reduction  An operator produces a set of sub problems, each of which have to be solved. - E.g. Tower of Hanoi
  • 8. Search - problem representation  State space graph  It is represented like nodes and edges where initial state to the goal state. It can also represent as tree graph.
  • 9. Search Strategy  A strategy is defined by picking the order of node expansion. Strategy is evaluated among the following dimensions.  Completeness- does it always find a solution if one exists?  Time complexity- no. of nodes generated.  Space complexity- max no. of nodes in memory.  Optimality- does it always find least cost solution?  Time and space is measured in ‘b’ – max branching factor of search tree. ‘d’- depth of least cost solution. ‘m’ – max depth of the state space may be (infinite)
  • 10. Which are the Search Types ?  Blind search algorithms are as follows:  In blind search the number of nodes can be extremely large, The order of expanding the nodes is arbitrary - Breadth First Search - Depth First Search  Heuristic search - Ordered Search - A* An optimal search  Consider State space graph as general graph i.e. nodes and points. Graphs can be directed undirected or mixed graph.
  • 11. Breadth-First Search  Breadth First Search (BFS) searches breadth-wise in the problem space. Breadth-First search is like traversing a tree where each node is a state which may a be a potential candidate for solution.  Breadth first search expands nodes from the root of the tree and then generates one level of the tree at a time until a solution is found. It is very easily implemented by maintaining a queue of nodes.  Initially the queue contains just the root. In each iteration, node at the head of the queue is removed and then expanded. The generated child nodes are then added to the tail of the queue.
  • 12. ALGORITHM: BREADTH-FIRST SEARCH  Create a variable called NODE-LIST and set it to the initial state.  Loop until the goal state is found or NODE-LIST is empty. • Remove the first element, say E, from the NODE- LIST. If NODE-LIST was empty then quit. • For each way that each rule can match the state described in E do:  - Apply the rule to generate a new state. - If the new state is the goal state, quit and return this state. - Otherwise add this state to the end of NODE-LIST
  • 13. Advantages : BFS  Breadth first search will never get trapped exploring the useless path forever.  If there is a solution, BFS will definitely find it out.  If there is more than one solution then BFS can find the minimal one that requires less number of steps.
  • 14. Disadvantages :BFS  The main drawback of Breadth first search is its memory requirement. Since each level of the tree must be saved in order to generate the next level, and the amount of memory is proportional to the number of nodes stored, the space complexity of BFS is O(bd).  As a result, BFS is severely space-bound in practice so will exhaust the memory available on typical computers in a matter of minutes.  If the solution is farther away from the root, breath first search will consume lot of time.
  • 15. DEPTH FIRST SEARCH  Depth First Search (DFS) searches deeper into the problem space.  BFS always generates successor of the deepest unexpanded node.  Depth First Search uses last-in first-out stack for keeping the unexpanded nodes.  More commonly, depth-first search is implemented recursively, with the recursion stack taking the place of an explicit node stack.
  • 16. ALGORITHM: DEPTH FIRST SEARCH  If the initial state is a goal state, quit and return success.  Otherwise, loop until success or failure is signalled. a) Generate a state, say E, and let it be the successor of the initial state. If there is no successor, signal failure. b) Call Depth-First Search with E as the initial state. c) If success is returned, signal success. Otherwise continue in this loop.
  • 17. ADVANTAGES  The advantage of depth-first Search is that memory requirement is only linear with respect to the search graph.  The time complexity of a depth-first Search to depth d is O(b^d) since it generates the same set of nodes as BFS.  If depth-first search finds solution without exploring much in a path then the time and space it takes will be very less.
  • 18. DISADVANTAGES  There is a possibility that it may go down the left-most path forever. Even a finite graph can generate an infinite tree.  Depth-First Search is not guaranteed to find the solution.  And there is no guarantee to find a minimal solution, if more than one solution exists.
  • 19. Bidirectional Search  The algorithms so far use forward reasoning, i.e. moving from the start node towards a goal node. some cases we could use backward reasoning, i.e. moving from the goal state to the start state.  Forward and backward reasoning can be combined into a technique called bidirectional search. - One starting from the initial state and searching forward - One starting from the goal state and searching backward The search terminates when the two graphs intersect
  • 20. Problems in Real World  There are some toy searching that we’ll see this technique are used to solve some real world problems like:  Route finding.(computer networks, airline travel planning system)  Layout problems (VLSI layout, furniture layout, packaging)  Assembly sequencing.(Assembly of electrical motors)  Task Scheduling.(Time tables, manufacturing)
  • 21. Water Jug Problem  Consider the following problem: A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a pump which has unlimited water which you can use to fill the jug, and the ground on which water may be poured. Neither jug has any measuring markings on it. How can you get exactly 2 gallons of water in the 4-gallon jug?  State Representation and Initial State – We will represent a state of the problem as a tuple (x, y) where x represents the amount of water in the 4- gallon jug and y represents the amount of water in the 3-gallon jug. Goal state as (2,y).
  • 22. Production Rules  (x,y)If x<4 -> (4,y)  (x,y)If y<3 ->(x,3)  (x,y)If x>0 ->(x-d,y)  (x,y)If y>0 ->(x,y-d)  (x,y)If x>0 ->(0,y)  (x,y)If y>0 ->(x,0)  (x,y)If(x+y>=4 and y>0) ->(4,y-(4-x))  (x,y)If (x+y>=3 and x>0) ->(x-(3-y),3)  (x,y)If(x+y<=4 and y>0) ->(x+y,0)  (x,y)If (x+y<=3 and x>0) ->(0,x+y)  (0,2)->(2,0)
  • 23. Solution 4 Gallon Jug 3 Gallon Jug 0 0 pump 4 0 1 3 1 0 4 Gallon jug 0 1 3 Gallon jug 4 1 2 3
  • 24. Search Tree : Water Jug Problem (0,0) (4,0) (0,3) (4,3) (0,0) (1,3) (4,3) (0,0) (3,0)
  • 25. 8 Puzzle Problem 1 3 5 1 2 3 2 7 4 4 5 6 6 8 7 8 Start State Goal State
  • 26. 8 Puzzle Problem  State space (S) Location of each of the 8 tiles(and the blank tile)  Start State (s) Starting configuration  Operators(O) Four Operators : Right, Left, Up, Down  Goals(G) one of the goal configuration
  • 27. 8 Queen Problem  Problem: Place 8 queens on a chess board so that none of them attack each other  Formulation- I - A state is an arrangement of 0 to 8 queens on the board - Operators add a queen to any square.  This formulation is not a systematic way to find the solution, it takes a long time to get the solution.
  • 28. 8 Queen Problem  Formulation – II - A state is an arrangement of 0-8 queen with no one attacked. - Operators place a queen in the left most empty column. - More systematic than formulation-I
  • 29. 8 Queen Problem  Formulation –III - A state is an arrangement of 8 queens on in each column. -Operators move an attacked queen to another square in the same column. -Keep on shuffling the queen until the goal is reached. - This formulation is more systematic hence , it is also called as Iterative Formulation.
  • 30. 8 Queen Problem : Solution
  • 31. Missionaries and Cannibals  Three missionaries and three cannibals find themselves on a side of river. They agreed to get to the other side of river. But missionaries are afraid of being eaten by cannibals so, the missionaries want to manage the trip in such a way that no. of missionaries on either side of the river is never less than the no. of cannibals on the same side. The boat is able to hold only 2 people at a time.
  • 32. Missionaries and Cannibals  State(#m,#c,1/0) #m – number of missionaries on first bank #c – number of cannibals on first bank  The last bit indicate whether the boat is in the first bank.  Operators • Boat carries (1,0) or (0,1) or (1,1) or (2,0) or (0,2)