0% found this document useful (0 votes)
76 views5 pages

Graph Primi Ves: Introduc On To Graph Search

The document discusses graph search algorithms. It introduces the generic graph search algorithm which explores all reachable vertices from a starting vertex without exploring any vertex twice. It then discusses two common graph search algorithms: breadth-first search (BFS) and depth-first search (DFS). BFS explores vertices in layers by using a queue, while DFS explores aggressively like a maze by using a stack. Both BFS and DFS have a running time of O(m+n) on a graph with m edges and n vertices.

Uploaded by

Siva Tarun
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views5 pages

Graph Primi Ves: Introduc On To Graph Search

The document discusses graph search algorithms. It introduces the generic graph search algorithm which explores all reachable vertices from a starting vertex without exploring any vertex twice. It then discusses two common graph search algorithms: breadth-first search (BFS) and depth-first search (DFS). BFS explores vertices in layers by using a queue, while DFS explores aggressively like a maze by using a stack. Both BFS and DFS have a running time of O(m+n) on a graph with m edges and n vertices.

Uploaded by

Siva Tarun
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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