Graph Foundations

What is a graph? Vertices, edges, and basic notation

Welcome to Graph Theory!

A graph is one of the most versatile structures in mathematics and computer science. At its core, a graph is simply a collection of vertices (also called nodes) connected by edges (also called links). This simple idea can model an incredible variety of real-world systems!

In this module, you'll build graphs from scratch, learn the essential terminology, and discover how graphs can be represented mathematically. Let's dive in!

What You'll Learn

šŸ”µ
Vertices & Edges
The building blocks of every graph
šŸ“–
Graph Terminology
Degree, neighbors, adjacency, and more
āž”ļø
Directed vs Undirected
When edge direction matters
šŸ“Š
Adjacency Matrices
Representing graphs as 2D arrays

Interactive Graph Builder

Build your own graph! Click on the canvas to add vertices, then drag from one vertex to another to create an edge. This is the foundation of graph theory - vertices connected by edges.

0
Vertices (V)
0
Edges (E)

How to Use

  • Click empty space to add a new vertex
  • Click and drag from one vertex to another to create an edge
  • Use Delete Mode to remove vertices (edges are removed automatically)
  • The graph notation is G = (V, E) where V = vertices, E = edges

Key Concept: Graph Notation

A graph is written as G = (V, E) where V is the set of vertices and E is the set of edges. Your current graph has 0 vertices and 0 edges.

Graph Terminology Explorer

Hover over vertices and edges to learn the key terminology. The highlighted elements show relationships like neighbors and incident edges.

Triangle (K3)

Complete graph with 3 vertices

|V| = 3|E| = 3

Hover to Explore

Move your mouse over vertices and edges to see their properties and terminology.

Vertex Terms

  • Degree: Number of edges connected to a vertex
  • Neighbor: A vertex connected by an edge
  • Adjacent: Two vertices connected by an edge

Edge Terms

  • Endpoints: The two vertices an edge connects
  • Incident: An edge is incident to its endpoints
  • Loop: An edge connecting a vertex to itself

Directed vs Undirected Graphs

Graphs can be undirected (edges have no direction) or directed (edges point from one vertex to another). Click a vertex, then click another to add an edge.

Undirected Graph

Edges: 4 | Edge notation: {u, v}

Directed Graph (Digraph)

Edges: 4 | Edge notation: (u, v) or u → v

Undirected: Degree

A
deg = 2
B
deg = 2
C
deg = 2
D
deg = 2

Degree = total number of edges connected

Directed: In-degree & Out-degree

A
in=1, out=1
B
in=1, out=1
C
in=1, out=1
D
in=1, out=1

In-degree = edges coming in, Out-degree = edges going out

Key Differences

Undirected

  • Edge {A, B} = {B, A}
  • One degree per vertex
  • Used for: friendships, roads

Directed

  • Edge (A, B) ≠ (B, A)
  • In-degree and out-degree
  • Used for: web links, followers

Adjacency Matrix Visualizer

An adjacency matrix represents a graph as a 2D array. Click cells to toggle edges and watch the graph update in real-time!

Adjacency Matrix

A
B
C
D
A
B
C
D

Click a cell to toggle the edge. Diagonal is always 0 (no self-loops).

Graph

|V| = 4|E| = 4

Matrix Properties

  • Symmetric: For undirected graphs, A[i][j] = A[j][i]
  • Diagonal: All zeros (no self-loops in simple graphs)
  • Space: O(V²) - uses VƗV cells regardless of edge count
  • Edge lookup: O(1) - just check A[i][j]

Why Use Adjacency Matrices?

Adjacency matrices are ideal for dense graphs (many edges) and algorithms that need fast edge lookups. For sparse graphs (few edges), adjacency lists are more space-efficient. The matrix also enables powerful linear algebra techniques - matrix powers reveal path counts between vertices!

What We've Learned

1. Graph Basics: A graph G = (V, E) consists of vertices V and edges E. Edges connect pairs of vertices to represent relationships.

2. Terminology: The degree of a vertex is the number of edges connected to it. Neighbors are vertices connected by an edge. Adjacent vertices share an edge.

3. Directed vs Undirected: In undirected graphs, edges have no direction (friendships). In directed graphs (digraphs), edges point from source to target (followers, web links).

4. Adjacency Matrix: A VƗV matrix where A[i][j] = 1 if there's an edge from vertex i to j. Symmetric for undirected graphs. Great for dense graphs and fast edge lookup.

Next Up: In the next section, you'll learn about graph properties like connectivity, special graph types (complete, bipartite, trees), and the famous Handshaking Lemma!