3.2.2 · D1Linear Data Structures

Foundations — Linked list — singly - node structure, traversal, insert head - tail - middle, delete

1,775 words8 min readBack to topic

Before you can read a single line of the parent topic, you must own every word and symbol it quietly assumes. This page builds them in order, each one earning its place before the next arrives.


1. Memory as a street of numbered houses

Everything starts here. When a program stores something, it lives in memory — think of memory as one long street where every house has a number painted on it. That number is called an address.

Figure — Linked list — singly -  node structure, traversal, insert head - tail - middle, delete

2. Pointer / reference — a house-number written on paper

Now that we have addresses, we need a way to hold one.

Figure — Linked list — singly -  node structure, traversal, insert head - tail - middle, delete

Read more in Pointers and References.


3. null — the arrow that points nowhere

Every chain must end. We need a special value meaning "there is no next house."


4. Node — one box holding a value and an arrow

Now we combine a value with a pointer. This is the parent's Node.

Figure — Linked list — singly -  node structure, traversal, insert head - tail - middle, delete

5. head — the only door you're given

You never hold all the nodes. You hold one pointer.


6. cur, prev — walking fingers on the chain

To do anything you slide a finger along the arrows.

Figure — Linked list — singly -  node structure, traversal, insert head - tail - middle, delete

The move cur = cur.next means: overwrite my finger's position with the address the current box points to — i.e. hop forward one box.


7. and Big-O — counting the work

The parent writes , , . Here is what those shapes mean.

Full detail in Big-O Notation.


8. The class blueprint — class, self, __init__

The parent's code uses Python object syntax. The bare minimum:


How these foundations feed the topic

Memory address

Pointer or reference

null end marker

Node data plus next

head first door

cur and prev walking fingers

Traversal insert delete

n count of nodes

Big-O growth shape

Everything on the left is a prerequisite; the arrows show what must be understood before the box it feeds. The parent topic lives in the bottom-right node — you now have every arrow leading into it.


Equipment checklist

Test yourself — read the left, answer before revealing the right.

What is an address in memory?
The house-number of a spot in memory — a plain integer identifying where a value lives.
What is a pointer (reference)?
A value that holds an address; following it means "go to the box at that house-number." Drawn as an arrow.
What does null / None mean, and what does it not mean?
A pointer to nothing ("no next box"). It does NOT mean the data is zero.
What two slots does a node have?
data (the value) and next (a pointer to the next node, or null).
Why can't a node behave like an array element?
An array computes positions with base + i*size; a node only stores one neighbour's address, so nodes may scatter anywhere and you must follow arrows.
What is head and why is losing it fatal?
The external pointer to the first node — the only entry point. Lose it and the whole chain becomes unreachable garbage.
What do cur and prev represent while walking?
cur = the box you're on now; prev = the box one step behind (needed for deletion since singly lists can't look backward).
What does cur = cur.next physically do?
Moves your finger to the box whose address the current box's next slot holds — one hop forward.
What is ?
The number of nodes currently in the list.
What do and mean?
= fixed work regardless of list length; = work grows in proportion to the number of nodes.
What does self mean inside a class method?
"This particular object" — self.data is this node's data slot.

Next, once these are solid: return to the parent topic, and later compare against a Doubly Linked List, a Stack using Linked List, and a Queue using Linked List.