Skip to main content
Discrete Math
CHAPTER 21 Beginner

Graph Theory Fundamentals

Updated: May 17, 2026
15 min read

# CHAPTER 21

Graph Theory Fundamentals

1. Introduction

We have spent 20 chapters dissecting localized mathematics: calculating the sum of arrays, finding the probability of a die roll, and predicting the output of Logic Gates. Now, we expand our architecture to a global, planetary scale. How does Facebook know who to recommend as a friend? How does Google Maps calculate the fastest drive from New York to LA? How do packets route across the global internet? They do not use standard arrays. They use Graphs. Graph Theory is the mathematics of interconnected networks. It is the absolute pinnacle of discrete mathematics, fundamentally tying Set Theory and Relations together into a unified geometric mapping engine.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define the mathematical components of a Graph: Vertices ($V$) and Edges ($E$).
  • Differentiate between Undirected and Directed Graphs (Digraphs).
  • Understand Weighted Graphs and their application to GPS routing.
  • Calculate the Degree of a Vertex and apply the Handshaking Lemma.

3. What is a Graph?

In discrete math, a Graph ($G$) is not an X/Y axis chart from high school algebra. A Graph is a collection of points connected by lines. Mathematically, a graph is defined as an ordered pair of two sets: $G = (V, E)$
  1. 1. $V$ (Vertices / Nodes): A set of distinct points. (e.g., Cities, IP Addresses, People).
  1. 2. $E$ (Edges): A set of lines connecting the points. (e.g., Highways, Fiber-optic cables, Friendships).

*Example:* $V = \{A, B, C\}$ $E = \{(A, B), (B, C)\}$ Node A is connected to Node B. Node B is connected to Node C.

4. Undirected vs. Directed Graphs

The physical geometry of the Edge fundamentally defines the routing limitations of the algorithm.

Undirected Graphs:

  • The connection is a plain line. It implies a two-way (Symmetric) street.
  • *Example:* Facebook Friends. If Alice is friends with Bob, Bob is automatically friends with Alice. Traffic can flow freely in both directions.

Directed Graphs (Digraphs):

  • The connection is an arrow ($\rightarrow$). It implies a strict one-way street.
  • *Example:* Twitter Followers. Alice follows Bob (Alice $\rightarrow$ Bob). But Bob does not follow Alice. To create a two-way street, you must draw a second independent edge pointing backward.

5. Weighted Graphs

A standard edge just proves a connection exists ($0$ or $1$). But what if some connections are physically longer or more expensive than others? We inject an integer value directly onto the edge. This is a Weighted Graph.
  • *Example:* GPS Routing. Node A (NY) connects to Node B (Chicago). The Edge weight is $790$ (miles).
The legendary algorithm "Dijkstra's Shortest Path" calculates routing strictly by mathematically summing these geometric edge weights to find the minimum integer payload!

6. The Degree of a Vertex

The Degree of a vertex is the exact number of edges physically touching it. If Node A has 5 lines connecting to it, its degree is 5.

*In Directed Graphs, we split this metric:*

  • In-Degree: Number of arrows pointing *towards* the node. (How many followers you have).
  • Out-Degree: Number of arrows pointing *away* from the node. (How many people you follow).

7. The Handshaking Lemma

The most famous theorem in basic Graph Theory. The Rule: If you sum up the degrees of every single vertex in an entire Undirected Graph, the final number is absolutely, mathematically guaranteed to be exactly double the number of edges ($2 \times |E|$).

*Why?* Because every physical Edge has exactly two ends! Every time you draw 1 line, you inherently add 1 degree to the node on the left, and 1 degree to the node on the right.

*The Corollary:* In any graph, the total number of vertices with an ODD degree must mathematically be an EVEN number. It is physically impossible to construct a graph otherwise!

8. Common Mistakes

  • Assuming visual layout matters: The physical drawing of a graph is irrelevant. You can draw Node A at the top of the page or the bottom of the page. You can make the edge squiggly or perfectly straight. In discrete math, all that matters is the mathematical Set mapping: Does $(A, B)$ exist in Set $E$? Yes or No. The geometry is abstract.

9. Exercises

  1. 1. Define a Directed Graph modeling the relations $V=\{1, 2, 3\}$ and $E=\{(1, 2), (2, 3), (3, 1)\}$. What is the In-Degree of node 2?
  1. 2. If an Undirected Graph possesses 10 Vertices, and every single Vertex has a Degree of 3, how many total Edges exist in the graph? (Hint: Use the Handshaking Lemma).

10. MCQs with Answers

Question 1

What are the two absolute, foundational Set structures required to mathematically define a discrete Graph ($G$)?

Question 2

When mapping a complex social network like Twitter (where User A can follow User B, without User B following User A), what specialized graph architecture MUST be deployed?

Question 3

If Google Maps is calculating the fastest route between two cities, what critical variable must be physically injected onto the graph's Edges to allow the algorithm to calculate distance/time constraints?

Question 4

What is the explicit mathematical definition of the "Degree" of a localized vertex within an Undirected Graph?

Question 5

In advanced Directed Graph architecture, how do algorithms quantify the metric representing a user's "Follower Count" (people pointing toward them)?

Question 6

According to the legendary mathematical "Handshaking Lemma", what is the guaranteed operational output if you sum the exact degree count of every single node inside an Undirected Graph?

Question 7

Based strictly on the physical mathematical limits imposed by the Handshaking Lemma, is it possible to construct an Undirected Graph containing exactly 3 nodes, where every node has a degree of 3?

Question 8

If an engineer is analyzing a Graph theoretically mapped as $V=\{A, B, C\}$ and $E=\{(A, B), (B, C)\}$, does the visual position of Node B on the physical computer screen alter the algorithm's routing math?

Question 9

Which branch of Discrete Mathematics, covered previously in Chapter 9, acts as the absolute foundational matrix physically generating the data required to build a Directed Graph?

Q10. True or False: In advanced Graph Theory, it is mathematically legal to draw an edge that loops directly back onto its own starting vertex, as well as multiple distinct parallel edges connecting the same two nodes. a) True. While "Simple Graphs" forbid these, "Multigraphs" and "Pseudographs" actively embrace self-looping edges and redundant parallel pathways to mathematically model complex architectures like multilane highways or redundant server backup cables. b) False. Graphs must remain perfectly simple arrays. Answer: a) True. While "Simple Graphs" forbid these, "Multigraphs" and "Pseudographs" actively embrace...

11. Interview Preparation

Top Interview Questions:
  • *Graph Representation:* "An interviewer asks you: How do you physically store a Graph inside a computer's RAM? You cannot store drawings." *(Answer: You must use advanced data structures! You either construct an 'Adjacency Matrix' (a massive 2D array mapping 1s and 0s for connections) or an 'Adjacency List' (an array where each node contains a Linked List of its neighbors). Matrix is fast for dense graphs, List is highly optimized for sparse graphs!)*

12. Summary

Graph Theory transforms abstract relationships into navigable geometric matrices. By defining Vertices and mapping their connections with Edges, software architects can model the entire physical internet, social media webs, and GPS grids. Mastering the Handshaking Lemma and Directed paths is the prerequisite to unleashing algorithmic bots to traverse these vast networks.

13. Next Chapter Recommendation

We have built the map. Now, we must release the algorithm to explore it. How does an AI systematically search a massive, sprawling network containing Millions of nodes without getting trapped in an infinite circular loop? In Chapter 22: Graph Traversal Algorithms, we will architect the legendary BFS and DFS engines.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·