### Representing directed graphs

• Di-graph representation

• Example:

• Di-graph:

 ``` 0 1 2 3 4 5 6 7 8 +- -+ | 0 1 0 1 0 0 0 0 0 | // 0 | 1 0 0 0 0 0 0 1 0 | // 1 | 0 0 0 0 0 1 0 0 0 | // 2 | 1 0 1 0 1 0 0 0 0 | // 3 M = | 0 0 0 0 0 0 0 0 1 | // 4 | 0 0 1 0 0 0 1 0 0 | // 5 | 0 0 0 0 0 0 0 0 0 | // 6 | 0 0 1 0 0 0 0 0 0 | // 7 | 1 0 0 0 0 0 0 0 0 | // 8 +- -+ ```

• Traversing a Di-graph

• The DFS and BFS algorithms are unaware (oblivious) of the direction of the edges

• In fact, the adjacency list and adjacency matrix are di-graph representations:

 One undirected edge in the graph is represented by 2 "edges" in the adjacency list and adjacency matrix

• Hence:

 We can use the same old DFS and BFS algorithms to traverse di-graphs

• Difference between directed and undirected graph

• Traversal in directed and undirected graphs:

 The traversal of a undirected graph from a node x will reach all nodes that can are connected to x by a path The traversal of a directed graph from a node x will reach only nodes that are reachable by a series of forward link

• Example:

Forward path: 0 → 3 → 2

But starting at node 2, we cannot reach node 0

• Note:

 Directed edges are like one-way street....