Nodes and Edges
The two building blocks of any graph: nodes are things, and edges are the relationships between them.
What is it?
A graph is one of the most fundamental structures in computer science and mathematics. At its core, every graph is made of just two ingredients: nodes (also called vertices) and edges (also called links or connections).1
A node represents a single entity --- a person, a city, a web page, a concept. An edge represents a relationship between two nodes --- a friendship, a road, a hyperlink, a prerequisite. That is the entire vocabulary. Everything else in graph theory builds on these two primitives.2
The simplicity is deceptive. With only nodes and edges you can model social networks, road maps, the internet, molecular structures, language dependencies, and knowledge systems. The power comes not from the parts themselves but from the patterns that emerge when you connect many of them together.1
In plain terms
Think of a corkboard with index cards pinned to it. Each card is a node. Each piece of string you stretch between two cards is an edge. The cards are things; the strings are how those things relate to each other.
At a glance
Core structure (click to expand)
graph LR A[Person A] ---|friendship| B[Person B] B ---|friendship| C[Person C] A ---|colleague| D[Person D] D ---|friendship| CKey: Circles are nodes (people). Lines are edges (relationships). The label on each edge describes the type of connection. This small graph has 4 nodes and 4 edges.
How does it work?
Nodes (vertices)
A node is the atomic unit of a graph. It represents a single entity --- anything that can be described and connected to something else. In a social network, each user is a node. In a road network, each intersection is a node. In a knowledge system, each concept card is a node.
Every node can carry properties (also called attributes). For example, a person node might store a name and age; a city node might store population and coordinates.
Think of it like...
A node is a pin on a map. It marks a location (an entity), and you can attach a small label to describe it, but on its own it just sits there --- it only becomes interesting when you connect it to other pins.
Edges (links)
An edge connects two nodes and expresses a relationship between them. Without edges, a graph is just a list of isolated items.2
Edges come in several flavours depending on the information they carry:
| Property | Options | What it means |
|---|---|---|
| Direction | Directed / Undirected | Does the relationship go one way or both ways? |
| Weight | Weighted / Unweighted | Does the relationship have a numeric cost, distance, or strength? |
| Label | Labelled / Unlabelled | Does the relationship have a name or type? |
Think of it like...
An edge is a hallway between two rooms. An undirected edge is an open hallway you can walk in both directions. A directed edge is a one-way door. A weighted edge is a hallway with a sign saying “200 metres” --- it tells you the cost of traversing it.
Directed vs undirected
In an undirected graph, every edge works in both directions. If Alice is friends with Bob, then Bob is friends with Alice. The relationship is symmetric.1
In a directed graph (or digraph), edges have a direction --- they go from one node to another. A Twitter follow is a good example: Alice can follow Bob without Bob following Alice.1
Example (click to expand)
Consider a university prerequisite system:
graph LR CALC1[Calculus I] -->|prerequisite for| CALC2[Calculus II] CALC2 -->|prerequisite for| CALC3[Calculus III] LINALG[Linear Algebra] -->|prerequisite for| CALC3The arrows show direction: you must take Calculus I before Calculus II. The relationship is not symmetric --- Calculus II is not a prerequisite for Calculus I.
Weighted vs unweighted
In an unweighted graph, all edges are treated equally. A friendship either exists or it does not.
In a weighted graph, each edge carries a number (the weight) that quantifies the relationship --- for instance, distance in kilometres, cost in currency, or strength of connection.2
Example (click to expand)
A delivery company models cities as nodes and roads as edges. Each edge weight is the driving time in minutes:
From To Weight (minutes) Zurich Bern 75 Bern Lausanne 65 Zurich Lausanne 140 Finding the fastest route between two cities means finding the path with the lowest total weight --- a problem solved by algorithms like Dijkstra’s.
Labelled edges
A labelled edge carries a name or type that describes what kind of relationship it represents. In a knowledge graph, edges might be labelled “is-a”, “part-of”, or “prerequisite-for”. Labels turn a generic connection into a meaningful statement.3
For example: Alice --[manages]--> Bob says something very
different from Alice --[reports-to]--> Bob, even though the same
two nodes are involved.
Degree of a node
The degree of a node is the number of edges connected to it. In a social network, a person with 500 friends has a degree of 500. In a directed graph, we distinguish between in-degree (edges coming in) and out-degree (edges going out).1
High-degree nodes are often the most important or influential --- think of a popular account on social media or a heavily linked Wikipedia article.
Adjacency
Two nodes are adjacent if they share a direct edge. The full list of which nodes are adjacent to which is called the adjacency list (or adjacency matrix when stored as a grid of numbers). These are the two most common ways computers store graph data internally.2
Why do we use nodes and edges?
Key reasons
1. Universal modelling. Almost any system of connected things can be described as nodes and edges --- social networks, road maps, supply chains, language structures, concept maps.
2. Pattern discovery. Once data is in graph form, algorithms can find shortest paths, detect clusters, identify bottlenecks, and rank importance automatically.1
3. Visual clarity. A graph diagram makes relationships immediately visible in a way that tables and lists cannot. Humans are wired to see patterns in connected shapes.
When do we use nodes and edges?
- When modelling relationships between entities (people, places, concepts, files)
- When building a knowledge graph or ontology that needs to represent “X is related to Y”
- When solving pathfinding problems (navigation, logistics, network routing)
- When analysing influence or centrality in a network (who is most connected?)
- When ordering tasks that have dependencies (build systems, course prerequisites)
Rule of thumb
If your data has things and connections between things, you are looking at a graph problem --- and nodes and edges are your starting vocabulary.
How can I think about it?
The subway map
A city subway map is a graph in plain sight.
- Each station is a node
- Each track segment between two stations is an edge
- The edge is undirected --- trains go both ways on the same track
- The edge is weighted --- the travel time between stations varies
- Transfer stations are high-degree nodes (many lines converge)
- Finding the fastest route from A to B is a classic graph search problem
When you use a transit app, it is running a graph algorithm on exactly this structure.
The family tree
A family tree is a directed graph.
- Each person is a node
- Each parent-child link is a directed edge (parent ⇒ child)
- The edges are labelled --- “mother-of”, “father-of”
- Degree tells you how many children or parents someone has
- Two people are adjacent if they are directly related (parent-child, not grandparent)
- Ancestry is a path through multiple directed edges
Unlike the subway map, these edges only go one direction: a parent is a parent of a child, not the other way around.
Concepts to explore next
| Concept | What it covers | Status |
|---|---|---|
| knowledge-graphs | How nodes and edges form a connected web of knowledge | stub |
| taxonomies | Hierarchical classification systems built on parent-child edges | stub |
| topological-sort | Ordering nodes so that every directed edge points forward | stub |
| databases | How connected data is stored and queried at scale | complete |
Some cards don't exist yet
A broken link is a placeholder for future learning, not an error.
Check your understanding
Test yourself (click to expand)
- Explain the difference between a node and an edge to someone who has never seen a graph diagram.
- Name three real-world systems that can be modelled as graphs, and identify what the nodes and edges represent in each case.
- Distinguish between a directed edge and an undirected edge. Give one example of each from everyday life.
- Interpret this statement: “Node X has an in-degree of 12 and an out-degree of 3.” What does that tell you about X’s role in the network?
- Connect nodes and edges to the concept of databases: how might a graph database differ from a traditional table-based database in the way it stores relationships?
Where this concept fits
Position in the knowledge graph
graph TD KG[Knowledge Graphs] --> NE[Nodes and Edges] KG --> TAX[Taxonomies] KG --> ONT[Ontologies] NE -.->|related| DB[Databases] NE -.->|related| TS[Topological Sort] style NE fill:#4a9ede,color:#fffRelated concepts:
- taxonomies --- hierarchies are a special case of directed graphs where edges represent “is-a” or “part-of” relationships
- topological-sort --- an algorithm that orders nodes in a directed acyclic graph so dependencies come first
- databases --- graph databases store data natively as nodes and edges rather than tables and rows
Sources
Further reading
Resources
- Data Structures 101: Graphs (freeCodeCamp) --- Visual, beginner-friendly walkthrough of graph types with diagrams
- Introduction to Graph Data Structure (GeeksforGeeks) --- Comprehensive reference covering adjacency representations and traversals
- DSA Graphs (W3Schools) --- Interactive tutorial with code examples for graph fundamentals
- Describing Graphs (Khan Academy) --- Mathematical perspective on graph notation and properties
- Graph Theory: The Math of Nodes and Edges (Ideasthesia) --- History and intuition behind graph theory, starting from the Konigsberg bridges
Footnotes
-
Cassingena Navone, E. (2019). Data Structures 101: Graphs --- A Visual Introduction for Beginners. freeCodeCamp. ↩ ↩2 ↩3 ↩4 ↩5 ↩6
-
GeeksforGeeks. (2024). Introduction to Graph Data Structure. GeeksforGeeks. ↩ ↩2 ↩3 ↩4
-
Wikipedia contributors. (2024). Graph (abstract data type). Wikipedia. ↩