C Graph Terminology

Intermediate
6 min read
Updated: Nov 2026
1 example

Vertices, Edges, and Paths

A graph G = (V, E) has vertices V and edges E. Two vertices joined by an edge are adjacent. The degree of a vertex is the number of edges touching it. A path is a sequence of vertices connected by edges; a cycle is a path that returns to its start. A graph is connected if every vertex can reach every other. The handshake lemma says the degree sum equals twice the edge count.

Remember
/* 0 --- 1
   |   /
   2 --- 3       V = {0,1,2,3}
                 E = {0-1, 0-2, 1-2, 2-3} */

Cheat Sheet

Keep these facts handy while you work with Graph Terminology in C.

TopicDetail
VertexA node
EdgeA connection
DegreeEdges at a vertex
CyclePath that returns to start

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Directed and Undirected Graphs.

Example 1 — Degrees and the handshake lemma

The sum of degrees is twice the number of edges.

C
#include <stdio.h>

int main(void) {
    int edges[][2] = {{0, 1}, {0, 2}, {1, 2}, {2, 3}};
    int m = 4, deg[4] = {0}, sum = 0;

    for (int i = 0; i < m; i++) {
        deg[edges[i][0]]++;
        deg[edges[i][1]]++;
    }
    for (int v = 0; v < 4; v++) {
        printf("degree(%d)=%d\n", v, deg[v]);
        sum += deg[v];
    }
    printf("sum of degrees=%d (2 x %d edges)\n", sum, m);
    return 0;
}

How It Works

  1. Each undirected edge is counted at both ends.
  2. The degrees 2, 2, 3, 1 add to 8.
  3. Eight is exactly twice the four edges.

Edge Cases & Pitfalls

Check these before relying on Graph Terminology in real programs.

loop

Self loops

A self loop adds 2 to a vertex's degree in an undirected graph.

multi

Parallel edges

Matrices cannot store multiple edges between the same pair without counts.

Key Takeaways

  • G = (V, E).
  • Degree counts edges.
  • Cycles and connectivity matter for algorithms.

One line: A graph G = (V, E) has vertices V and edges E.

Frequently Asked Questions

The number of edges incident to that vertex.
A path that starts and ends at the same vertex without repeating edges.
Continue with "C Directed and Undirected Graphs" next. Store directed edges one way and undirected edges both ways. The C Graphs hub lists every topic in order.

Next: Directed and Undirected Graphs

Store directed edges one way and undirected edges both ways.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful