Vous êtes sur la page 1sur 3

Uniform-Cost Search

Uniform-Cost Search Algorithm

If all the edges in the search graph do not have the same cost then breadth-first search
generalizes to uniform-cost search. Instead of expanding nodes in order of their depth from the
root, uniform-cost search expands nodes in order of their cost from the root. At each step, the
next step n to be expanded is one whose cost g(n) is lowest where g(n) is the sum of the edge
costs from the root to node n. The nodes are stored in a priorit !ueue. This algorithm is also
"nown as #i$"stra%s single-source shortest algorithm.
&henever a node is chosen for expansion b uniform cost search, a lowest-cost path to that node
has been found. The worst case time complexit of uniform-cost search is '(b
(m), where c is
the cost of an optimal solution and m is the minimum edge cost. )nfortunatel, it also suggests
the same memor limitation as breadth-first search.
Breadth First Search
Breadth First Search (*+,) searches breadth-wise in the problem space. *readth-+irst search is
li"e traversing a tree where each node is a state which ma a be a potential candidate for
solution. *readth 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 ver easil implemented b maintaining a
!ueue of nodes. Initiall the !ueue contains $ust the root. In each iteration, node at the head of
the !ueue is removed and then expanded. The generated child nodes are then added to the tail of
the !ueue.
Algorithm: Breadth-First Search
1. Create a variable called NODE-LIST and set it to the initial state.
2. Loop until the goal state is ound or NODE-LIST is e!pt".
a. #e!ove the irst ele!ent$ sa" E$ ro! the NODE-LIST. I NODE-LIST %as
e!pt" then &uit.
b. 'or each %a" that each rule can !atch the state described in E do(
i) Appl the rule to generate a new state.
ii) If the new state is the goal state, !uit and return this state.
iii) 'therwise add this state to the end of -'#.-/I,T
,ince it never generates a node in the tree until all the nodes at shallower levels have been
generated, breadth-first search alwas finds a shortest path to a goal. ,ince each node can be
generated in constant time, the amount of time used b *readth first search is proportional to the
number of nodes generated, which is a function of the branching factor b and the solution d.
,ince the number of nodes at level d is b
, the total number of nodes generated in the worst case
is b 0 b
0 b
03 0 b
i.e. '(b
) , the asmptotic time complexit of breadth first search.
*readth +irst ,earch
/oo" at the above tree with nodes starting from root node, 4 at the first level, A and * at the
second level and 5, #, . and + at the third level. If we want to search for node . then *+, will
search level b level. +irst it will chec" if . exists at the root. Then it will chec" nodes at the
second level. +inall it will find . at the third level.
Advantages of Breadth-First Search
1. )readth irst search %ill never get trapped e*ploring the useless path orever.
2. I there is a solution$ )'S %ill deinitel" ind it out.
+. I there is !ore than one solution then )'S can ind the !ini!al one that re&uires
less nu!ber o steps.
Disadvantages of Breadth-First Search
1. The !ain dra%bac, o )readth irst search is its !e!or" re&uire!ent. Since
each level o the tree !ust be saved in order to generate the ne*t level$ and the
a!ount o !e!or" is proportional to the nu!ber o nodes stored$ the space
co!ple*it" o )'S is O-b
.. /s a result$ )'S is severel" space-bound in practice
so %ill e*haust the !e!or" available on t"pical co!puters in a !atter o !inutes.
2. I the solution is arther a%a" ro! the root$ breath irst search %ill consu!e lot o
Refer: http://intelligence.worldofcomputing.net/ai-