Professional Documents
Culture Documents
AI LAb Bfs Ucs
AI LAb Bfs Ucs
Afm:
To pevsovm Breadth inst sooch ond Uniçorm
Cost Seaich sime for the given graph using
Python
Alqovithm Fvetices and ac weiqhted
8F. Get the nD.
from the useY
91apb as adja cency matne
a sel
sele
queue and
2.
2 Ceate an empt y
to keep tiack oF visited nodes
node to the gueue
3. Add the stasling
a nd mank it as visited
While fhe ueue is not empty
fYom the front
a)Dequeue a node
he Queue the qoal, totwn
b) I the node
node
the
all the unvsit ed
cElse, itevate thvo ugh
the node and ndd Them to
nei qhbours oF as
Mavk ea eh neighboun
the 9ueue
visited
an d he go
the que ue s empty
5. I
rot arn Oone O an
been found,
has not
the gpal was not
in di catiom that
Teached
olP
Sample TlP
&roph otce No. o vovtices Total cest- 9
Solutron poath
Input the adj Matix
o, ,,5.6)
frovevso ot
=(o,,23,4,5,,
2 0 o O
O O 2 O O
2
node 0
Enlo the starting -
3
(A) 4
4
2
Total eost 8
Alaovithm
Unioim Cosl Soavch
vovtices and oighted
. Get 1he Dumber o
Ugen
malix fiom
91qph as 0djacency to
Quouo (haop in Pythen)
, Cteate a piovid y
visited and
nodes to be
keep rack visited nodes
track oF the
get to keep
stavting node to the pricnit y
3. Add the
maik it
and
ueue with Cost
nod e and
Unvisited neighbours upd dted
Ces-
their
pionity Queue
wth
the
neigh bour aS visited
Hak each
is
and
emptyand
empty
the
he
ueue
the priovity
5 1 retuxn
Teluin none
none
o on
been found,
has
has not
goal
goal
the gal
hot reached
indicatron
thaf
UCS Unifoim
Cost Seavdh
A)
3
A A C-B
A-C-E-B /2
Jtoiation - A-c-B-E-F
Cor
GH
A -C-a ED F -
haveical path
Total cost 8
ofP
omple IP:
Solution poth . , 2, 4,5,6J
Veilices: 8
No. or
Tiaversal path- [o,1, 1, 4,3,5,6]
Adj matrx
3 o 00 0 O
DDO 4 o0 o
o0
OO
0O 2 0
ooo oo 5
nodo- 0
ntor clotiq
node 6
Scal