Chapter 2 Search Techniques
Chapter 2 Search Techniques
Search Techniques
-Mrs. Anagha Patil
CO2: Apply an appropriate problem-solving
method and knowledge-representation scheme.
Implementation
Choosing
the solution
Identification
of solution
Analyze the
problem
Define the
problem
Bidirectional Search
Algorithm
Ans: S-A-D-B-C
Advantages:
• It requires very less memory.
• It takes less time to reach to the goal node than BFS.
Disadvantages:
• There is the possibility that many states keep re-occurring and there is no guarantee of
finding the solution.
• DFS algo goes for deep down searching and sometime it may go to the infinite loop.
3/3/2024 Anagha Patil, VCET 19
Performance measures of DFS
(i) Completeness : DFS is complete if the search tree is finite, it implies
that for a given finite search, DFS will have a solution if it exists.
(ii) Optimality : DFS is not optimal, it means that the number of steps in
reaching the solution, or the cost spent in reaching it is high.
(iii) Time complexity : The time complexity of DFS, if the entire tree is
traversed, is O (V) where V is the number of nodes.
For a directed graph, the sum of the sizes of the adjacency lists of all
nodes is E. So, the time complexity in this case is
O (V) + O (E) = O (V + E)
For an undirected graph, each edge appears twice.
(iv) Space complexity : For DFS, which goes along a single ‘branch’ all the
way down and uses a stack implementation, the height of the tree matters.
The space complexity for DFS is O (h) where h is the maximum height of the
tree.
3/3/2024 Anagha Patil, VCET 20
Breadth First Search(BFS)
• BFS is simple strategy in which the root node is expanded first, then all
the successors of the root node are expanded next, then their successors,
and so on.
• BFS involves search through a tree one level at a time. We traverse
through one entire level of children nodes first, before moving onto
traverse through the grand children nodes.
• Breadth first search is an algorithm for node that satisfies a given
property. It starts at the tree root and explores all nodes at the present
depth prior to moving on to nodes at the next depth level.
• BFS uses Queue-data structure for finding the shortest path. BFS can be
used to find single source shortest path in an un-weighted graph, because
in BFS, we reach a vertex with minimum number of edges from a source
vertex.
Disadvantages:
• It requires lot of memory.
• It needs lots of time if the solution is
Fig. Order in which nodes are visited in BFS
far away from the root node.
• The time complexity needed to run uniform cost search is: O(b(1 + C / ε))
Where: b - branching factor, C - optimal cost, ε - cost of each step
3/3/2024 Anagha Patil, VCET 30
Depth Limited Search(DLS)
• In infinite state spaces, depth-first search method fails. This failure
can be alleviated by supplying depth-first search with a pre -
determined depth limit l.
• Nodes at depth l are treated as if they have no successors.
• Thus depth-first search can be viewed as a special case of depth-
limited search with l = ∞.
• Depth-limited search can terminate with two kinds of failure :
(i) the standard failure value which indicates no solution;
(ii) the cut-off failure value which indicates no solution within the
depth-limit.
Step 1 : Let A be initial node and O the goal node and H is the
intersection node.
Step 2 : We start searching simultaneously from start to goal node and
backwards from goal node to start node.
Step 3 : When the forward search and backward search intersect at
one node, then searching stops.
Disadvantages
• Implementation of the bidirectional search tree is difficult.
• Goal state should be known in advance.
Step3
Step1
Total cost
8 + 6.5 + 3 + 0 = 17. 5
optimal path
S→D→E→F→G
Remark : Here we have to find
optimal (greedy) search. And the path
S → D → E → F → G is optimal.
3/3/2024 Anagha Patil, VCET 72
(1) If we have chosen the path
S → A → B → E → F → G, then
H(A) = 10, H (B) = 6, H(E) = 6, H (F) = 3; H (G) = 0
And the total cost = 10 + 6 + 6.5 + 3 = 25.5
(2)OR, if we have chosen the path
S → D → A → B → E → F → G; then
H (D) = 4, H (A) = 3, H (B) = 4, H (E) = 5, H (F) = 4 and H (G) = 0
Then the total cost = 4 + 3 + 4 + 5 + 4 = 21
(3) For any other path, the total cost would have been greater than 17. 5
S → D → E → F → G is optimal path and optimal cost is 17.5
Step1 Step7