1. Representation of graphs G=(V,E)
- adjacency lists—sparse graphs; directed, undirected, weighted; memory requiresθ(V+E);
- adjacency matrix—dense graph
2. Breadth-first search
Analysis
queue operations is O(V), scanning adjacency list is O(E), total running time of BFS is O(V+E).
3. Depth-first search
Analysis θ(V+E);
breadth-first search's predecessor subgraph forms a tree
depth-first search's predecessor is composed of several trees
a directed graph is acyclic if and only if a depth-first search yields no "back" edges