00:00

Types of Graph in Data Structure

Last updated:

Graphs come in many varieties, depending on whether edges have a direction or a weight, whether cycles are allowed, and how the vertices are connected. The list below defines the common types; each comes with a small example diagram.

Types of Graph in Data Structure

  1. Finite Graph: A graph whose vertex set and edge set are both finite. Every graph stored in a computer is finite.

    Finite graph with seven vertices A to G
  2. Infinite Graph: A graph with infinitely many vertices or edges, such as an endless grid. Such graphs appear in mathematics and are handled in programs only by generating the part that is needed.

    Part of an infinite grid graph whose edges continue in every direction
  3. Trivial Graph: A graph with exactly one vertex and no edges, the smallest possible non-empty graph.

    Trivial graph with the single vertex A
  4. Directed Graph: A graph in which every edge has a direction, from one vertex to another; it is also called a digraph. An edge (u, v) lets you go from u to v but not back unless (v, u) also exists.

    Directed graph whose edges are arrows between vertices A, B, C and D
  5. Undirected Graph: A graph whose edges have no direction: an edge {u, v} connects u and v both ways, like a two-way road.

    Undirected graph with vertices A to E connected by plain lines
  6. Weighted Graph: A graph in which every edge carries a number (its weight), such as a distance, time or cost. Shortest-path and minimum-spanning-tree algorithms work on weighted graphs.

    Weighted graph: A-B 10, A-C 20, B-C 30, B-D 40, C-D 50
  7. Cyclic Graph: A graph that contains at least one cycle, a path that starts and ends at the same vertex without reusing an edge.

    Cyclic graph: A, B, D and C connected in a cycle
  8. Acyclic Graph: A graph with no cycles. A connected, undirected acyclic graph is a tree.

    Acyclic graph: A-B, A-C and B-D with no cycle
  9. Directed Acyclic Graph: A directed graph with no directed cycle, usually called a DAG. DAGs model dependencies such as build steps, course prerequisites or task schedules, and their vertices can be put in topological order.

    Directed acyclic graph with arrows A to B, A to C and D to C
  10. Simple Graph: An undirected graph with no self-loops and at most one edge between any pair of vertices.

    Simple graph on four vertices A, B, C, D with one edge per pair
  11. Multi Graph: A graph that allows more than one edge (parallel edges) between the same pair of vertices. Under the most common convention a multigraph has no self-loops; a graph that also has loops is a pseudograph.

    Multigraph with two parallel edges between A and B and between C and D
  12. Connected Graph: An undirected graph in which there is a path between every pair of vertices.

    Connected graph on vertices A, B, C, D
  13. Disconnected Graph: An undirected graph in which at least one pair of vertices has no path between them. It splits into two or more connected components.

    Disconnected graph: A, B, C, D connected to each other and vertex E isolated
  14. Complete Graph: A simple undirected graph in which every pair of distinct vertices is joined by an edge. With n vertices every vertex has degree n − 1 and the graph has n(n − 1)/2 edges; it is written Kn.

    Complete graph on five vertices A to E
    Complete graph on four vertices A to D
  15. Null Graph: A graph that has vertices but no edges at all. (A graph with a single vertex and no edges is the trivial graph above.)

    Null graph: five vertices A to E and no edges
  16. Pseudo Graph: A graph that may contain self-loops (an edge from a vertex to itself) and, usually, parallel edges as well.

    Pseudograph with a self-loop at C and two parallel edges between A and B
  17. Regular Graph: A graph in which every vertex has the same degree. If every degree is k, the graph is called k-regular.

    2-regular graph: A, B, D and C connected in a cycle, every vertex has degree 2
  18. Subgraph: A graph H is a subgraph of G if every vertex of H is a vertex of G and every edge of H is an edge of G.

    A graph on A, B, C, D (circled part) and one of its subgraphs