270 likes | 284 Views
Explore different types of records and their usage in graphs. Learn about searching algorithms and the importance of order in data structures.
E N D
Types of Records One link – For stack and queue. Two links – For double ended queue. Many links:
Searching in a Graph A 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 x for all unmarked w adjacent to x do D INSERT(w) end end
Depth-First Search D is LIFO: D PUSH(v) While D≠Ø do x POP(D) visit and mark x for all unmarked w adjacent to x do D PUSH(w) end end A B C E F D
Breadth-First Search D is FIFO: D ENQUEUE(v) While D≠Ø do x DEQUEUE(D) visit and mark x for all unmarked w adjacent to x do D ENQUEUE(w) end end A B C E F D
אינפי 1 לינארית 1 מבוא לחישוב מבני נתונים לינארית 2 אינפי 2 מיון טופולוגי • כידוע יש באוניברסיטה לכל קורס דרישות קדם • נניח שאני מעוניין לקחת קורס אחד לסמסטר • תן אלגוריתם שיגיד איזה קורס לקחת באיזה סמסטר. אינפי 1 לינארית 1 אינפי 2 לינארית 2 מבני נתונים מבוא לחישוב
Algorithm • Topological-Sort() • { • Call DFS to compute finish time for each vertex • Insert vertex finished into the beginning of linked list • Return the linked list of vertices • } • הזמן זהה לחיפוש לעומק והוא O(V+E).
Socks Undershorts Watch Shoes Pants Shirt Belt Tie Jacket Example
Socks Undershorts Watch Shoes Pants Shirt Belt Tie Socks Undershorts Shoes Pants watch Shirt Tie Jacket Belt Jacket Example