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


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.

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:

PropertyOptionsWhat it means
DirectionDirected / UndirectedDoes the relationship go one way or both ways?
WeightWeighted / UnweightedDoes the relationship have a numeric cost, distance, or strength?
LabelLabelled / UnlabelledDoes 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

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

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

ConceptWhat it coversStatus
knowledge-graphsHow nodes and edges form a connected web of knowledgestub
taxonomiesHierarchical classification systems built on parent-child edgesstub
topological-sortOrdering nodes so that every directed edge points forwardstub
databasesHow connected data is stored and queried at scalecomplete

Some cards don't exist yet

A broken link is a placeholder for future learning, not an error.


Check your understanding


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:#fff

Related 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

Footnotes

  1. Cassingena Navone, E. (2019). Data Structures 101: Graphs --- A Visual Introduction for Beginners. freeCodeCamp. 2 3 4 5 6

  2. GeeksforGeeks. (2024). Introduction to Graph Data Structure. GeeksforGeeks. 2 3 4

  3. Wikipedia contributors. (2024). Graph (abstract data type). Wikipedia.