What Are Primitive Data Structures (Revisited, But Deeper)
Role of Primitives as Building Blocks
Read aloud is unavailable in this browser.
From Atoms to Architecture
In the previous pages, we established what primitive data structures are and why they're called "primitive." Now we turn to perhaps the most practical aspect of this understanding: how primitives combine to form every complex data structure you will ever encounter.
This is not metaphorical. Every array, linked list, tree, graph, hash table, heap, trie, and bloom filter—without exception—is constructed from primitives. Understanding this building-block relationship transforms how you see data structures: not as magic incantations to be memorized, but as logical constructions from simple, understandable components.
By the end of this page, you will: (1) Understand how primitives combine to form composite types, (2) See concrete examples of primitives within common data structures, (3) Recognize the role of pointers/references as the 'glue' between primitives, (4) Appreciate the universality of the primitive basis, and (5) Gain a new mental model for approaching any data structure.
Why this matters:
When you encounter a new data structure, the instinct might be to treat it as a black box—memorize its operations, memorize its complexities. But this approach is fragile. Forget a detail, and you're lost.
Understanding the building-block principle enables:
- Derivation over memorization: You can reason about operations from structure
- Debugging insight: When something goes wrong, you know what's actually happening
- Implementation capability: You can build data structures, not just use them
- Innovation: You can modify or create new structures when needed
Let's see how the building blocks work.
The Compositional Principle
The relationship between primitives and complex data structures follows what we'll call the compositional principle:
Every data structure is a composition of primitives, organized according to rules that determine how those primitives relate to each other and which operations are efficient.
This principle has three components:
1. Primitives as content
Data structures hold data. That data, at the bottom level, is primitives:
- An array of integers holds integers
- A tree of strings holds characters (as strings are character sequences)
- A graph with weighted edges holds vertex identifiers (integers) and weights (floats)
2. Pointers/references as connections
Beyond storing primitives, data structures create relationships between primitives. These relationships are implemented via pointers (memory addresses), which are themselves primitive-like values.
- A linked list node has a
nextpointer—an address (integer) pointing to another node - A tree node has
leftandrightpointers—addresses pointing to child nodes - A graph adjacency list has pointers to neighbor lists
Pointers are the "glue" that connects primitive values into structured wholes.
3. Rules as organization
What distinguishes data structures isn't the primitives themselves—it's how they're organized:
- An array organizes primitives contiguously by index
- A linked list organizes primitives by explicit next-pointers
- A binary search tree organizes primitives such that left < parent < right
- A hash table organizes primitives by hash function mapping
The primitives are the same; the rules differ.
Any data structure can be understood through this lens: What primitives does it hold? (Content) How are they connected? (Pointers) What rules govern the organization? (Invariants) This three-part analysis works for every data structure you'll ever encounter.
Visual representation of the principle:
┌─────────────────────────────────────────────────────────────┐
│ DATA STRUCTURE │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ ORGANIZATIONAL RULES │ │
│ │ (indexing, ordering, hashing, balancing, etc.) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ governs how these connect: │
│ ▼ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Primitive│◄──►│ Primitive│◄──►│ Primitive│ ... │
│ │ Value │ │ Value │ │ Value │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ ▲ ▲ ▲ │
│ │ │ │ │
│ ┌────┴────┐ ┌────┴────┐ ┌────┴────┐ │
│ │ Pointer │ │ Pointer │ │ Pointer │ │
│ │(address)│ │(address)│ │(address)│ │
│ └─────────┘ └─────────┘ └─────────┘ │
│ │
│ Primitives + Pointers + Rules = Data Structure │
└─────────────────────────────────────────────────────────────┘
This diagram applies to every data structure. The specifics change; the pattern remains.
Pointers: The Primitive That Connects Primitives
Before examining specific data structures, we must understand pointers (or references, in managed languages). Pointers play a unique role: they're primitive-like values (fixed-size integers representing memory addresses) that enable primitives to reference each other.
What is a pointer?
A pointer is a value that holds a memory address—the location where some other value resides.
Memory:
Address 1000: [42] ← an integer
Address 1004: [1000] ← a pointer TO that integer
│
└─── "The value at address 1004 is 1000,
which is the address where 42 lives"
Pointers enable indirection: one value points to another, creating linkages between data.
Pointers as primitives:
From a type-system perspective, pointers share many primitive characteristics:
- Fixed size: On a 64-bit system, all pointers are 64 bits (8 bytes)
- Direct hardware support: Pointer arithmetic uses CPU integer operations
- Atomic: A pointer is a single value, not decomposable into fields
The key difference: pointers have semantic meaning beyond their numeric value. The integer 1000 is just 1000. The pointer 1000 means "look at address 1000."
Why pointers are essential:
Without pointers, we could only have contiguous collections (arrays). Every element would have to be adjacent. But many data structures require non-contiguous organization:
- Linked lists: nodes scattered in memory, connected by pointers
- Trees: parent-child relationships via pointers
- Graphs: vertices connected by edge pointers
- Hash tables with chaining: buckets pointing to overflow lists
Pointers free us from contiguity constraints, enabling diverse structural organizations.
| Data Structure | What Pointers Connect | Why Pointers Are Needed |
|---|---|---|
| Linked List | Node to next node | Enables insertion/deletion without shifting |
| Doubly Linked List | Node to next and previous | Enables bidirectional traversal |
| Binary Tree | Node to left and right children | Represents hierarchical relationships |
| Graph (adjacency list) | Vertex to list of neighbors | Represents arbitrary connections |
| Hash Table (chaining) | Bucket to overflow chain | Handles collisions with linked elements |
| Trie | Node to child nodes for each character | Represents prefix relationships |
In languages like Java, Python, or JavaScript, you work with 'references' rather than raw pointers. References are essentially pointers with restrictions (no arithmetic) and safety guarantees (garbage collection). The underlying principle is identical: one value contains the address of another. References are the managed version of pointers.
Arrays: The Simplest Primitive Composition
Let's examine specific data structures through the building-block lens, starting with the simplest: arrays.
What an array is (at the primitive level):
An array is a contiguous block of primitives, all of the same type, indexed by integers.
Array of 5 integers: [10, 20, 30, 40, 50]
Memory layout (assuming 4-byte integers):
Address: 1000 1004 1008 1012 1016
┌─────┬─────┬─────┬─────┬─────┐
│ 10 │ 20 │ 30 │ 40 │ 50 │
└─────┴─────┴─────┴─────┴─────┘
[0] [1] [2] [3] [4]
Primitive inventory:
- Content: 5 integers (20 bytes total)
- Connection: Implicit—elements are adjacent, no explicit pointers needed
- Rule: Element i is at address (base + i × element_size)
Arrays are special: their connection mechanism is implicit (contiguity) rather than explicit (pointers). This simplicity enables O(1) random access.
Why O(1) access works:
Given:
- Base address: 1000
- Element size: 4 bytes
- Index: 3
Address of element 3 = 1000 + (3 × 4) = 1012
This address calculation uses:
- One integer multiplication (index × size)
- One integer addition (base + offset)
Both are primitive operations—O(1). No traversal, no searching, just arithmetic.
Building blocks revealed:
An array is perhaps the purest demonstration of primitives as building blocks:
- Take n primitives of the same type
- Place them contiguously in memory
- Use integer arithmetic for access
No magic—just primitives arranged according to a simple rule.
Arrays are so fundamental that many other data structures are built ON TOP of arrays. Dynamic arrays, hash tables, heaps, and adjacency matrices all use arrays internally. Understanding arrays as 'primitives arranged contiguously' prepares you to understand these higher structures as 'arrays with additional rules.'
Linked Lists: Pointer-Connected Primitives
Where arrays use implicit contiguity, linked lists use explicit pointers to connect primitives scattered in memory.
What a linked list is (at the primitive level):
A linked list is a sequence of nodes, where each node contains:
- A primitive value (the data)
- A pointer to the next node
Linked list: 10 → 20 → 30
Memory (nodes scattered, connected by pointers):
Address 1000: Address 2050: Address 1500:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ value: 10 │ │ value: 20 │ │ value: 30 │
│ next: 2050 ─────┼─────►│ next: 1500 ─────┼─────►│ next: null │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Primitive inventory:
- Content: 3 integers (values: 10, 20, 30)
- Connection: 3 pointers (addresses: 2050, 1500, null)
- Rule: Each node points to the next; traversal follows pointers
Each node contains exactly 2 primitives (or primitive-like values):
- Value:
int(4 bytes) - Next: pointer (8 bytes on 64-bit system)
Total per node: 12 bytes. Total for 3 nodes: 36 bytes.
Compare to array:
- Array of 3 integers: 12 bytes (just the values)
- Linked list of 3 integers: 36 bytes (values + pointers)
This is the space overhead of explicit connections. Linked lists trade memory for flexibility.
| Aspect | Array | Linked List |
|---|---|---|
| Primitives for data | n elements | n elements |
| Primitives for connection | 0 (implicit contiguity) | n pointers |
| Total space for n ints | 4n bytes | 12n bytes (64-bit) |
| Access method | Address arithmetic | Pointer traversal |
| Access time | O(1) | O(n) |
| Insertion/deletion (known position) | O(n) shift | O(1) pointer update |
Building blocks revealed:
A linked list is:
- Primitives (data values) packaged with
- Primitives (pointers) that link packages together
The "linked" in "linked list" refers to the pointer connections. Without pointers, you can't have a linked list—you'd just have scattered, disconnected values.
Doubly linked lists:
Add one more pointer per node (to previous), and you get bidirectional traversal:
Node:
┌────────────────────────┐
│ prev: pointer (8 bytes)│
│ value: int (4 bytes) │
│ next: pointer (8 bytes)│
└────────────────────────┘
Total: 20 bytes per node
More primitives (pointers) per node → more capabilities (backward traversal) at higher space cost.
Trees: Hierarchical Primitive Structures
Trees extend the linked structure concept to create hierarchical relationships. A binary tree node has one value and two pointers (left child, right child).
What a binary tree is (at the primitive level):
Binary tree:
50
/
30 70
/
20
Each node (primitive decomposition):
┌─────────────────────────┐
│ value: int (4 bytes) │
│ left: pointer (8 bytes) │
│ right: pointer (8 bytes)│
└─────────────────────────┘
Total: 20 bytes per node
Primitive inventory:
- Content: 4 integers (50, 30, 70, 20)
- Connection: 8 pointers (2 per node)
- Rule: Varies by tree type (BST: left < parent < right)
Why trees work:
The power of trees comes from their organizational rule combined with their structure:
Binary Search Tree rule: For any node:
- All values in left subtree < node's value
- All values in right subtree > node's value
This rule, applied recursively, creates a structure where:
- Finding a value requires following only one path (left or right at each step)
- Path length is proportional to tree height
- Balanced trees have height O(log n)
All from primitives:
- The values being compared: primitives (integers)
- The comparison operation: primitive operation (<, >)
- The navigation choices: primitive pointer values
- The result: O(log n) search using only primitive operations
A linked list is a degenerate tree where each node has at most one child. A binary tree generalizes this to at most two children. An n-ary tree generalizes to n children. The building blocks are the same—value + pointers. The number of pointers per node determines possible structure.
More pointers, more structure:
Different tree variants use different pointer configurations:
| Tree Type | Pointers per Node | Additional Primitives |
|---|---|---|
| Binary Tree | 2 (left, right) | — |
| Binary Tree with parent | 3 (left, right, parent) | Enables upward traversal |
| N-ary Tree | N (child array) | Array of pointers |
| Red-Black Tree | 2 + color bit | Boolean/int for color |
| AVL Tree | 2 + height/balance | Integer for balance factor |
More complex trees add more primitives (balance factors, colors, parent pointers) to maintain additional invariants. But they're still just primitives connected by pointers.
Hash Tables: Computed Primitive Mappings
Hash tables showcase a different kind of primitive composition: using computation on primitives to determine organization.
What a hash table is (at the primitive level):
A hash table consists of:
- An array of buckets (primitives or pointers)
- A hash function (primitive integer arithmetic)
- Collision handling (more primitives/pointers)
Hash table for integer keys, separate chaining:
Buckets: Array of pointers
┌───────┬───────┬───────┬───────┬───────┐
│ null │ ptr │ null │ ptr │ null │
└───────┴───┬───┴───────┴───┬───┴───────┘
[0] [1]│ [2] [3]│ [4]
│ │
▼ ▼
┌───────┐ ┌───────┐
│key: 11│ │key: 23│
│val: X │ │val: Y │
│next:──┼───► │next: │
└───────┘ │ └───────┘
▼
┌───────┐
│key: 21│
│val: Z │
│next:──┼──► null
└───────┘
Primitive inventory:
- Array: m pointers (bucket array, where m = table size)
- Nodes: Each contains key (primitive), value (primitive), next (pointer)
- Hash function: Computes bucket index from key using integer arithmetic
The hash function:
For key k, bucket index = hash(k) % m
Simple example: hash(k) = k % 5
hash(11) = 11 % 5 = 1 → bucket [1]
hash(21) = 21 % 5 = 1 → bucket [1] (collision!)
hash(23) = 23 % 5 = 3 → bucket [3]
The hash function is pure primitive arithmetic:
- Modulo operation: primitive integer division
- More complex hashes: multiplication, XOR, bit shifts—all primitive operations
Why O(1) average case:
- Compute hash: O(1) primitive arithmetic
- Access bucket: O(1) array index
- Search within bucket: O(1) if few collisions
When load factor (n/m) is kept low and hash function distributes well:
- Most buckets have 0 or 1 elements
- Bucket search is O(1)
Building blocks revealed:
A hash table combines:
- An array (contiguous primitives/pointers)
- Linked lists (pointer-connected nodes)
- A hash function (primitive arithmetic)
It's not a new primitive—it's a sophisticated organization of existing primitives. The "magic" of O(1) lookup comes from using computation (hash function) to eliminate traversal.
Hash tables introduce a new connection mechanism: computation. Instead of following pointers, we calculate where data should be. But the calculation itself uses primitive operations. There's no escape from primitives—even 'smart' data structures reduce to them.
The Universal Reduction Principle
We've seen primitives as building blocks in arrays, linked lists, trees, and hash tables. But this isn't coincidence—it's a universal principle:
Every data structure, no matter how complex, can be reduced to primitives connected by pointers, organized according to rules.
Let's verify this with more structures:
| Data Structure | Data Primitives | Connection Primitives | Organizational Rule |
|---|---|---|---|
| Stack | Values (ints, etc.) | Array or next-pointers | LIFO: last in, first out |
| Queue | Values | Array indices or pointers | FIFO: first in, first out |
| Heap | Values | Array indices (implicit tree) | Min/max at root, heap property |
| Graph (adj list) | Vertex IDs, weights | Array of lists, list pointers | Edges as vertex pairs or adjacency |
| Graph (adj matrix) | Edge weights or booleans | 2D array (implicit) | Matrix[i][j] = edge from i to j |
| Trie | Characters | Child pointers (array or map) | Edges labeled by characters |
| Bloom Filter | Bits (booleans) | Array indices (computed) | Probabilistic membership via hashes |
| B-Tree | Keys, values | Child pointers, sibling pointers | Balanced, multi-way, disk-friendly |
The pattern holds universally:
In every case:
- Data is stored as primitives (integers, floats, characters, booleans)
- Connections are made via pointers (explicit) or indices (implicit in arrays)
- Rules determine what connections exist and how they're maintained
The sophistication—what makes a red-black tree different from a heap, or a B-tree different from a trie—lies entirely in the rules. The building blocks are always the same primitives.
Implications:
-
Learning transfer: Once you understand how primitives compose, learning new structures becomes easier. You're just learning new rules.
-
Implementation insight: When implementing a data structure, you're really just managing primitives and pointers according to rules.
-
Debugging power: When a data structure behaves unexpectedly, the bug is in how primitives/pointers are being managed.
-
Design creativity: To invent a new data structure, define new rules for organizing primitives.
You now have X-ray vision for data structures. When you see a 'balanced binary search tree,' you don't see a black box—you see nodes containing integers and pointers, organized so that left < parent < right and height is logarithmic. The mystique dissolves into mechanics.
KEEP LEARNING
Keep learning for free.
Read the complete lesson, save your notes and pick up where you left off with a free account. No card needed.