1. Graph G = ( V, E) representation: Adjacency list and Adjacency matrix. It is better to use adjacency list when the graph is not dense. Adjacency matrix supports checking an edge between vertex i and j in O(1) time.
2. BFS. Use queue to implement in O(V + E) time.
Applications: shortest paths. Many real world problems can be converted into graph and then solve them by finding shortest paths.
3. DFS. Use stack to implemnt in O(V + E) time.
Applications: topological sort, which can be used for finding topological order.
Algorithm:
1) Call DFS(G) to compute finishing time v.f for each vertex v.
2) as each vertex is finished, insert in onto the front of a linked list.
3) return the linked list of vertics.
Find Strongly connected components.
Algorithm:
1) call DFS(G) to compute finishing time u.f for each vertex u
2) compute (G^T)
3) call DFS(G^T), but in the main loop of DFS, consider the vertices in order of deceasing u.f(as computed in 1).
4) output the vertices of each tree in the depth-first forest formed in 3) as a separate strongly connected component.