Chapter 1: The World of Nodes and Edges - What is a Graph?
Imagine you are exploring a mysterious island. On this island, every creature, every tree, and every hidden cave is connected in a web of relationships. Some paths are clear and well-trodden, while others are secret and winding. How would you map this intricate network? You would likely start by marking important locations—perhaps a sparkling waterfall, a tall mountain, or a cozy burrow—and then draw lines to show how you can travel from one place to another. What you have just created, even if you didn’t know it, is a graph. Graphs are not just drawings; they are powerful mathematical tools that help us understand, analyze, and navigate the connected world around us. From the friendships in your classroom to the routes of a global airline, graphs provide a universal language for relationships. This chapter will serve as your passport to this fascinating world. We will begin by uncovering the simplest yet most profound elements of graphs: nodes (the points) and edges (the connections). Through child-friendly examples—like a friendship web, a family tree, and a subway map—we will see how graphs naturally model real-life systems. We will also explore key properties such as direction, weight, and cycles, which add richness and realism to our models. By the end, you will grasp the core metaphor that guides this entire book: a graph is, at its heart, a story about how things connect. And as we will discover in later chapters, this story becomes especially powerful when we use it to understand the inner workings of neural networks—the very systems that mimic the human brain. So, let us start our journey by asking: what exactly is a graph?
The Building Blocks: Nodes as the "Who" and "What"
At its most fundamental level, a graph is composed of two types of objects: nodes (also called *vertices*) and edges. Let us first meet the nodes. A node is simply a point in the graph that represents an entity—something tangible or intangible that we want to study. Think of nodes as the characters in a story, the cities on a map, or the ingredients in a recipe. They are the "what" or "who" in the narrative of connections. In mathematical terms, we often denote the set of all nodes as $V$ (for vertices). For example, if we are modeling a classroom, each student is a node. If we are mapping a family tree, each person is a node. Even abstract concepts like "ideas" or "events" can be nodes if we wish to explore their relationships.
To make this concrete, consider your own classroom. You might have students named Alex, Ben, Chloe, Dan, and Emma. Each of these students is a distinct node. We could represent them as dots on a piece of paper, each labeled with a name. But a node is more than just a dot; it carries identity. In graph theory, nodes are usually drawn as circles or squares, but their visual representation is flexible—what matters is that each node is unique and can be distinguished from others. Sometimes nodes have additional properties, called *attributes*, such as age, favorite color, or height. These attributes are not part of the graph structure itself but can be stored alongside the node for richer analysis. For instance, in a graph of students, we might note that Alex is 10 years old, Ben loves soccer, and Chloe has a pet hamster. These details make our graph more descriptive, but the core graph only cares about the nodes as distinct points.
Now, let us expand our view beyond the classroom. In a family tree, nodes represent individuals. Your grandparents, parents, siblings, and even distant cousins are all nodes. The relationships between them—parent-child, sibling-sibling, spouse-spouse—will be captured by edges, which we will discuss soon. But notice how naturally the idea of nodes fits: each person is a discrete unit in the family network. In a subway map, each station is a node. Grand Central Terminal, Times Square, and Brooklyn Bridge–City Hall are all nodes. They are the places where journeys begin, end, or transfer. In a food web in an ecosystem, nodes could represent species—rabbits, foxes, carrots, wolves—and edges would show who eats whom. Even in the digital world, your social media profile is a node, and the websites you visit are nodes in the vast graph of the internet.
The beauty of nodes lies in their simplicity and generality. They can represent almost anything: physical objects (a book, a planet), abstract concepts (a thought, a goal), or even events (a birthday party, a historical moment). This flexibility is why graphs are so widely used. When we build a graph, the first step is always to identify the nodes: what are the fundamental entities we care about? Once we have our nodes, we can begin to ask: how are they connected? That is where edges come in.
The Glue: Edges as the "How" and "Why"
If nodes are the characters, then edges are the relationships that bind them together. An edge is a line that connects two nodes, representing some kind of interaction, association, or dependency between them. In mathematical notation, we often denote the set of all edges as $E$. Edges answer the questions "how are these nodes related?" and "why do they matter to each other?" Without edges, nodes would be isolated points with no context—like names in a phone book with no phone numbers. Edges give the graph its meaning and structure.
Let us return to the classroom friendship example. Suppose Alex and Ben are friends. We can represent this friendship with an edge connecting the node for Alex and the node for Ben. But what does that edge look like? In an undirected graph—where relationships are mutual—we draw a simple line without an arrow. This line says, "Alex is friends with Ben, and Ben is friends with Alex." Friendship is typically reciprocal, so an undirected edge makes sense. Now, what about Chloe? If Chloe is also friends with Alex and Ben, we add edges between Chloe and each of them. Suddenly, we have a tiny web of connections. We could even add Dan and Emma and map all the friendships in the class. This graph now tells a story: who is popular (many edges), who is isolated (few edges), and which groups of friends form cliques (densely connected subsets).
But not all relationships are mutual. Consider social media follows. On platforms like Twitter or Instagram, if Sam follows Taylor, that does not necessarily mean Taylor follows Sam back. This is a directed relationship. In graph terms, we use a directed edge, drawn as an arrow pointing from the source node to the target node. So, if Sam follows Taylor, we draw an arrow from Sam’s node to Taylor’s node. This direction adds a layer of information: it captures asymmetry. In a directed graph, the edge from A to B is distinct from the edge from B to A. We might have both (mutual follows), only one (one-way follow), or neither (no connection). This idea extends to many real-world systems: a road that allows travel only one way, an email sent from you to a friend, or a hyperlink from one webpage to another.
Edges can also carry weights, which are numerical values that quantify some aspect of the relationship. A weighted graph assigns a number to each edge, representing things like distance, cost, strength, or capacity. For example, in a subway map, the edge between two stations might be weighted by the travel time in minutes. If it takes 5 minutes to go from Times Square to Grand Central, but 12 minutes to go from Times Square to Union Square, those edges have different weights. In a friendship graph, we could weight edges by how close the friends are—maybe on a scale of 1 to 10—to indicate the strength of the bond. A weight of 1 might mean "acquaintances," while 10 means "best friends forever." Weighted edges allow graphs to model not just connectivity but also the intensity or cost of connections.
Sometimes edges have labels instead of or in addition to weights. A label is a textual tag that describes the type of relation