You are on page 1of 5

Craph rlmluves

lnLroducuon Lo
Craph Search
ueslgn and Analysls
of AlgorlLhms l
1lm 8oughgarden
1. Check lf a neLwork ls connecLed (can geL Lo anywhere from
anywhere else )
2. urlvlng dlrecuons
3. lormulaLe a plan [e.g., how Lo ll ln a Sudoku puzzle]
-- nodes = a parually compleLed puzzle -- arcs = lllng ln one
new sequence
4. CompuLe Lhe pleces" (or componenLs") of a graph
-- clusLerlng, sLrucLure of Lhe Web graph, eLc.
A lew Mouvauons
8acon
number = 2
1lm 8oughgarden
Cenerlc Craph Search
Coals : 1) nd everyLhlng ndable from a glven
sLarL verLex
2) don'L explore anyLhlng Lwlce

Cenerlc AlgorlLhm (glven graph C, verLex s)
-- lnlually s explored, all oLher veruces
unexplored
-- whlle posslble :
-- choose an edge (u,v) wlLh u explored
and v unexplored
-- mark v explored
Coal:
C(m+n) ume
( lf none, halL)
1lm 8oughgarden
Clalm : aL end of Lhe algorlLhm, v explored <==> C has a paLh from
( C undlrecLed or dlrecLed ) s Lo v
roof : (=>) easy lnducuon on number of lLerauons ( you check )
(<=) 8y conLradlcuon. Suppose C has a paLh from s Lo v:



8uL v unexplored aL end of Lhe algorlLhm. 1hen Lhere exlsLs an
edge (u,x) ln wlLh u explored and x unexplored.
8uL Lhen algorlLhm would noL have LermlnaLed, conLradlcuon.
Cenerlc Craph Search (con'd)
unexplored
explored
1lm 8oughgarden
noLe : how Lo choose among Lhe
posslbly many fronuer" edges ?

8readLh-llrsL Search (8lS)
-- explored nodes ln layers"
-- can compuLe shorLesL paLhs
-- can compuLe connecLed componenLs of an undlrecLed graph

uepLh-llrsL Search (ulS)
-- explore aggresslvely llke a maze, backLrack only when necessary
-- compuLe Lopologlcal orderlng of a dlrecLed acycllc graph
-- compuLe connecLed componenLs ln dlrecLed graphs
8lS vs. ulS
C(m+n) ume
uslng a queue
(lllC)
C(m+n) ume uslng a sLack (LllC)
(or vla recurslon)
explored
unexplored
Crosslng
edges

You might also like