0% found this document useful (0 votes)
18 views15 pages

Chapter 4

Uploaded by

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

Chapter 4

Uploaded by

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

Uniform Cost Search algorithm

 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 the least.

Cost of a node is defined as:

cost(node) = cumulative cost of all nodes from root


cost(root) = 0
Uniform Cost Search algorithm

Path: S -> A -> B -> G


Cost: 5
Example
 In the above figure, consider S to be the start node and G to be
the goal state. From node S we look for a node to expand, and we
have nodes A and G, but since it’s a uniform cost search, it’s
expanding the node with the lowest step cost, so node A becomes
the successor rather than our required goal node G.

 From A we look at its children nodes B and C. Since C has the


lowest step cost, it traverses through node C.

 Then we look at the successors of C, i.e., D and G. Since the cost


to D is low, we expand along with node D. Since D has only one
child G which is our required goal state we finally reach the goal
state D by implementing UFS Algorithm.

 If we have traversed this way, definitely our total path cost from S
to G is just 6 even after traversing through many nodes rather
than going to G directly where the cost is 12 and 6<<12(in terms
of step cost). But this may not work with all cases.
Uniform Cost Search algorithm
Advantages:
 UCS is complete only if is no loop with zero or no
negative cost.

 Disadvantages:
 Explores options in every “direction”.
 No information on goal location
Informed Search Algorithms
Here, the algorithms have information on the goal
state, which helps in more efficient searching. This
information is obtained by a heuristic.
In this section, we will discuss the following search
algorithms.
1.Greedy Search
2.A* Tree Search
Search Heuristics: In an informed search, a
heuristic is a function that estimates how close a
state is to the goal state.
Greedy Search algorithm
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


Greedy Search algorithm
Find the path from S to G using greedy search. The
heuristic values h of each node below the name of the
node.
Greedy Search algorithm
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 a lower
heuristic cost. Finally, from
E, we go to G(h=0). This
entire traversal is shown in
the search tree below, in
Path: S -> D -> E -> G blue.
Greedy Search algorithm

Advantage: Works well with informed search


problems, with fewer steps to reach a goal.

Disadvantage: Can turn into unguided DFS in the


worst case.
A* Tree Search algorithm
 A* Tree Search, or simply known as A* Search,
combines the strengths of uniform-cost search and
greedy search.
 In this search, the heuristic is the summation of the
cost in UCS, denoted by g(x), and the cost in the
greedy search, denoted by h(x). The summed cost is
denoted by f(x).
Heuristic: f(x) = g(x) + h(x)
Here, h(x) is called the forward cost and is an estimate
of the distance of the current node from the goal node.
And, g(x) is called the backward cost and is the
cumulative cost of a node from the root node.
A* Tree Search algorithm
Find the path to reach from S to G using A* search.
A* Tree Search algorithm
Starting from S,
the algorithm
computes g(x) +
h(x) for all nodes
at each step,
choosing the node
with the lowest
sum. The entire
work is shown in
the table below.
Path: S -> D -> B -> E ->
G
Cost: 7
Example
The numbers written on
edges represent the
distance between the
nodes.
The numbers written on
nodes represent the
heuristic value.

Find the most cost-


effective path to reach
from start state A to final
state J using A* Algorithm.
Path H(X) G(x) F(x)=h(x) + g(x)

A->B 8 6 14

A->F 6 3 9

A->F->G 5 4 9

A->F->H 3 10 13

A->F->G->I 1 7 8

A->F->G->I- 0 10 10
>J
A->F->G->I- 3 12 15
>E
3 9 12
A->F->G->I-
>H

You might also like