It can check edge in the graph in O(1) time, but it wastes space. We can use tree instead of hash table, tree’s search can be done in O(lg n) time.
June 20, 2007
Exercises 22.1-6
Start from one node u, if there is one edge (u,v), then u is not sink. If there is no edge (u,v), then v is not sink. Since checking one edge can reduce the candidates by one. We can check at most O(V) edges and find the sink.
June 19, 2007
Exercises 22.1-5
Adjacency matrix: Given the matrix A, then A’s square is the solution. Time complexity is .
Adjacency list: In graph G if node u is adjacent to v, then v’s neighbors will become u’s neighbors. Hence we can replace v with v’s neighbors into u’s neighbor. The running time is O(EV).
Exercises 22.1-4
Like DFS, we construct a DFS tree and record all tree edges and back edges. Then E’ = tree edges + back edges. The running time is O(V+E).