Graphs: Terminology & Representations
- Vertex (Node): A fundamental unit in a graph representing an entity. It can represent anything, such as a city, person, or object.
- Edge (Link): A connection between two vertices in a graph. It can be directed or undirected, weighted or unweighted.
- Directed Graph (Digraph): A graph where edges have a direction associated with them, indicating a one-way relationship between vertices.
- Undirected Graph: A graph where edges have no direction, indicating a two-way relationship between vertices.
- Weighted Graph: A graph where edges have weights or costs associated with them, representing the cost of traversing from one vertex to another.
- Degree of a Vertex: The number of edges incident to a vertex. In directed graphs, there are separate in-degree and out-degree measures.
- Path: A sequence of vertices connected by edges, representing a route from one vertex to another.
- Cycle: A path that starts and ends at the same vertex, without visiting any other vertex more than once.
Representations of Graphs:
- Adjacency Matrix: A two-dimensional array where each cell represents the presence or absence of an edge between two vertices. It’s efficient for dense graphs but consumes more memory for sparse graphs.
- Adjacency List: A collection of lists or arrays, where each list/array represents a vertex, and its elements represent the vertices adjacent to it. It’s efficient for sparse graphs but may require more time for certain operations.
- Edge List: A simple list of edges, where each edge is represented by a pair of vertices (or triplet with weights). It’s straightforward but less efficient for certain operations compared to adjacency list or matrix.
Graphs & Multi-graphs:
- Graph: In graph theory, a graph typically refers to a simple graph where each pair of vertices is connected by at most one edge.
- Multi-graph: A multi-graph is a generalization of a graph where multiple edges between the same pair of vertices are allowed. These edges may have different weights or attributes.
- Parallel Edges: In a multi-graph, parallel edges refer to multiple edges connecting the same pair of vertices.
- Self-loop: An edge that connects a vertex to itself in a graph or multi-graph.
Multi-graphs can represent more complex relationships between entities, where multiple interactions or connections between the same pair of entities are possible. They are useful in various applications, including network analysis, transportation systems, and social networks. However, they may require more sophisticated algorithms and data structures for manipulation compared to simple graphs.