- Undirected Graphs
average degree:
- DFS, depth first search
example trace:
The output is 0-2-1-3-5-4.
DFS implementation:
Proposition A. DFS marks all the vertices connected to a given source in time proportional to the sum of their degrees.
Why the preprocessing time is E + V?
For example:
The source is s. s has adjacent vertices A, C, D.
The trace will be:
Stack: s a b c d
output: s a b c d e v
- BFS, breadth-first search:
Depth-first search. Put unvisited vertices on a stack.
Breadth-first search. Put unvisited vertices on a queue.
Shortest path. Find path from s to t that uses fewest number of edges.