CS 3 BFS Aloritm Mrk Rkopp
Brt-First Sr (BFS) HIGHLIGHTED ALGORITHM
3 Pt Plnnin W'v sn BFS in t ontxt o inin t sortst pt trou mz? S??
4 Pt Plnnin W xplor t 4 niors s on irtion 3 3 3 S 3 3 3 3 3 F I you on t know wr F is n wnt to in t sortst pt, you v to o it tis wy 3 3 3 Uninorm sr or sortst pt: Brt-irst
5 Brt-First Sr Now lt's nrliz BFS to ritrry st o onntions/niors Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin t minimum numr o ops (.k.. pt/istn) rom t strt vrtx to vry otr vrtx Dpt :
6 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin t minimum numr o ops (.k.. pt) rom t strt vrtx to vry otr vrtx Dpt : Dpt :,
7 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin t minimum numr o ops (.k.. pt) rom t strt vrtx to vry otr vrtx Dpt : Dpt :, Dpt :,,,
8 Brt-First Sr Givn rp wit vrtis, V, n s, E, n strtin vrtx, u BFS strts t u ( in t irm to t lt) n ns-out lon t s to nrst niors, tn to tir niors n so on Gol: Fin t minimum numr o ops (.k.. pt) rom t strt vrtx to vry otr vrtx Dpt : Dpt :, Dpt :,,, Dpt 3: 3
9 Dvlopin t Aloritm Ky i: Must xplor ll nrr niors or xplorin urtrwy niors From w in n Computr n only o on tin t tim so w v to pik itr or to xplor Lt s sy w pik w will in Now wt vrtx soul w xplor (i.. visit niors) nxt? Cois r n. C!! (i w on t w won t in sortst pts.. ) Must xplor ll vtis t pt i or ny vrtis t pt i+ Dpt : Dpt :, Dpt :,,, Dpt 3:
Dvlopin t Aloritm Kp irst-in / irst-out list (.k.. FIFO/irst-om irst-srv/quu/qu/t.) o niors oun Pull vrtis out o t ront o t list n xplor tir niors wn w in nw niorin vrtx w it to t k o t list W on t wnt to put vrtx in t quu mor tn on so w ll n to "mrk" vrtx t irst tim w nountr it w will only llow unmrk vrtis to put in t quu
Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q - - - - - Mrk u s oun n pt = Wil(Q is not mpty) - - x = Rmov ront itm Q: For nior, y, o x I vrtx y is not oun A y to k o t list, Q Mrk y s oun y sttin pt o y = pt o x +
Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) - - - - - x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
3 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) - - - - x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
4 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) - x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
5 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) - x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
6 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) 3 x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
7 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) 3 x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
8 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) 3 x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun A y to k o t list, Q Q: Mrk y s oun y sttin pt o y = pt o x +
9 Brt-First Sr Aloritm: Initiliz ll vrtis s not oun y sttin pt = - Crt list, Q A strt vrtx, u to Q Mrk u s oun n pt = Wil(Q is not mpty) 3 x = Rmov ront itm X = For nior, y, o x I vrtx y is not oun Q: A y to k o t list, Q Mrk y s oun y sttin pt o y = pt o x +
Tips or Implmntin BFS in PA5 Aumnt Usrs wit 'pt' n 'prssor' il Dpt = - mns not oun yt Prssor is ID o Usr wo oun you 'rins' vtor rprsnts s For t BFS quu w soul us Dqu Pl strt vrtx ID in it Continu prossin vrtis wil t qu is not mpty Pull out vrtis rom ront Pus nwly oun rins/usrs to t k Atr wil loop, n trvrs t prssor tril or look t t pt o spii usr