Upload
sibyl-powell
View
219
Download
0
Embed Size (px)
Citation preview
Graphs
Types of RecordsOne link – For stack and queue.
Two links – For double ended queue.
Many links:
Order is important
Searching in a GraphA Generic algorithm:Let G=(V,E) be the graph.Let D be a data structure (we’ll later
see which one).
For unmarked vertex v:VISIT(v)
end
VISIT(v)D INSERT(v)While D≠Ø do
x REMOVE(D)visit and mark xfor all unmarked w adjacent to x do
D INSERT(w)end
end
Depth-First SearchD is LIFO:D PUSH(v)While D≠Ø do
x POP(D)visit and mark xfor all unmarked w adjacent to x do
D PUSH(w)end
end
A
B C
D E F
Breadth-First SearchD is FIFO:D ENQUEUE(v)While D≠Ø do
x DEQUEUE(D)visit and mark xfor all unmarked w adjacent to x do
D ENQUEUE(w)end
end
A
B C
D E F
מיון טופולוגיכידוע יש באוניברסיטה לכל •
קדםקורס דרישות
נניח שאני מעוניין לקחת • לסמסטר אחדקורס
שיגיד איזה אלגוריתםתן •קורס לקחת באיזה סמסטר.
אינפי 1
אינפי 2
לינארית 2
לינארית 1
מבני נתונים
מבוא לחישוב
אינפי 1
לינארית 1
לינארית 2
מבוא לחישוב
מבני נתונים
אינפי 2
Topological-Sort )( {
Call DFS to compute finish time for each vertexInsert vertex finished into the beginning of linked listReturn the linked list of vertices
{
.)O)V+Eהזמן זהה לחיפוש לעומק והוא
Algorithm
Example
Undershorts
Watch
Socks
Jacket
Tie
Shirt
Belt
ShoesPants
ExampleUndershorts
WatchSocks
Jacket
Tie
ShirtBelt
ShoesPants
Socks JacketUndershorts Pants Shoes watch Shirt Belt Tie