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

Types of Search Algo

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Types of Search Algo

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

.

UNIT-II: SEARCH ALGORITHMS ----------------------------------------------------------------


------------------------------------------------

∙A search problem consists of:


∙ A State Space. Set of all possible states where you can be. ∙ A Start State.
The state from where the search begins. ∙ A Goal Test. A function that
looks at the current state returns whether or not it is the goal state.
∙ The Solution to a search problem is a sequence of actions, called the plan
that transforms the start state to the goal state. ∙ This plan is achieved
through search algorithms.

Types of search algorithms

There are far too many powerful search algorithms are there , few of the
fundamental search algorithms, divided into two categories, as shown below.

Uninformed Search Algorithms

The search algorithms in this section 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/or length of
actions. Uninformed search is also called Blind search. The following uninformed
search algorithms are discussed in this section.
1. Depth First Search
2. Breath First Search
3. Uniform Cost Search

Each of these algorithms will have:


∙A problem graph, containing the start node S and the goal node G. ∙ A strategy,
describing the manner in which the graph will be traversed to get to G .
∙ A fringe, which is a data structure used to store all the possible states (nodes)
that you can go from the current states.
∙ A tree, that results while traversing to the goal node. ∙ A solution
plan, which the sequence of nodes from S to G.

Depth First Search


Depth-first search (DFS) is an algorithm for traversing or searching tree or graph
data structures. The algorithm starts at the root node (selecting some arbitrary
node as the root node in the case of a graph) and explores as far as possible along
each branch before backtracking.
Example:
Question. Which solution would DFS find to move from node S to node G if run on
the graph below?

Solution. The equivalent search tree for the above graph is as follows. As DFS
traverses the tree “deepest node first”, it would always pick the deeper branch until
it reaches the solution (or it runs out of nodes, and goes to the next branch). The
traversal is shown in blue arrows.
Path: S -> A -> B -> C -> G

Completeness: DFS is complete if the search tree is finite, meaning for a given finite search tree, DFS
will come up with a solution if it exists.
Optimality: DFS is not optimal, meaning the number of steps in reaching the solution, or the cost spent
in reaching it is high.

Breadth First Search

Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data
structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to
as a ‘search key’), and explores all of the neighbor nodes at the present depth prior to moving
on to the nodes at the next depth level.
Example:

Question. Which solution would BFS find to move from node S to node G if run on the graph
below?
Solution. The equivalent search tree for the above graph is as follows. As BFS traverses the
tree “shallowest node first”, it would always pick the shallower branch until it reaches the
solution (or it runs out of nodes, and goes to the next branch). The traversal is shown in blue
arrows.

Path: S -> D -> G

Completeness: BFS is complete, meaning for a given search tree, BFS will come up with a
solution if it exists.

Optimality: BFS is optimal as long as the costs of all edges are equal. Uniform

Cost Search

UCS is different from BFS and DFS because here the costs come into play. In other words,
traversing via different edges might not have the same cost. The goal is to find a path where
the cumulative sum of costs is least.
Cost of a node is defined as:
cost(node) = cumulative cost of all nodes from root cost(root) = 0
Example:
Question. Which solution would UCS find to move from node S to node G if run on the graph
below?

Solution. The equivalent search tree for the above graph is as follows. Cost of each node is the
cumulative cost of reaching that node from the root. Based on UCS strategy, the path with least
cumulative cost is chosen. Note that due to the many options in the fringe, the algorithm explores most
of them so long as their cost is low, and discards them when a lower cost path is found; these discarded
traversals are not shown below. The actual traversal is shown in blue.
Path: S -> A -> B -> G

Disadvantages:

Informed Search Algorithms

Here, the algorithms have information on the goal state, which helps in more efficient searching.
This information is obtained by something called a heuristic. In this section, we will discuss the
following search algorithms.
1. Greedy Search
2. A* Tree Search
3. A* Graph Search
Search Heuristics: In an informed search, a heuristic is a function that estimates how close a
state is to the goal state. For examples – Manhattan distance, Euclidean distance, etc. (Lesser
the distance, closer the goal.)
Different heuristics are used in different informed algorithms discussed below.

Greedy Search

In greedy search, we expand the node closest to the goal node. The “closeness” is estimated
by a heuristic h(x) .
Heuristic: A heuristic h is defined as
h(x) = Estimate of distance of node x from the goal node.
Lower the value of h(x), closer is the node from the goal.
Strategy: Expand the node closest to the goal state, i.e. expand the node with lower h
value.
Example:
Question. Find the path from S to G using greedy search. The heuristic values h of each
node below the name of the node.
Solution. Starting from S, we can traverse to A(h=9) or D(h=5). We choose D, as it has the lower
heuristic cost. Now from D, we can move to B(h=4) or E(h=3). We choose E with lower heuristic cost.
Finally, from E, we go to G(h=0). This entire traversal is shown in the search tree below, in blue.

Path: S -> D -> E -> G


Advantage: Works well with informed search problems, with fewer steps to reach a goal.
Disadvantage: Can turn into unguided DFS in the worst case.

You might also like