Directed and undirected graphs are two types of mathematical structures used to represent relationships between entities. The key distinction between them lies in the presence or absence of directionality in the edges connecting the nodes (vertices).
-
Directed Graph (Digraph):
- In a directed graph, each edge has a direction or an orientation, indicating a one-way relationship between two nodes.
- The edges are represented by arrows, and the arrow points from one node (the source) to another node (the target or destination).
- The order of the nodes in the pair (u, v) matters, meaning the edge from node u to node v is different from the edge from node v to node u.
- Directed graphs are often used to model situations where there is a clear direction in the relationship, such as in networks, flows, or dependencies.
-
Undirected Graph:
- In an undirected graph, edges have no direction, and the relationship between nodes is symmetric.
- Edges are represented by simple lines connecting nodes, and the order of the nodes in the pair (u, v) does not matter.
- Undirected graphs are commonly used to model relationships where the interaction or connection between two nodes is mutual or bidirectional.
In summary, the key difference is that directed graphs have edges with a specific direction, while undirected graphs have edges without direction. The choice between using a directed or undirected graph depends on the nature of the relationships being modeled and the context of the problem being solved.