What is a linked list?
A linked list is a chain of nodes. Each node holds a value and a pointer to the next node — like train cars hooked together, or sticky notes with arrows between them. You only keep a reference to the first car (the head). To reach anything else, you walk the arrows.
- Node
- A value plus a link to another node (or
null) - Head
- The first node — your only starting handle on the list
- Next / pointer
- The arrow from one node to the following node
See it as a chain
Picture sticky notes on a desk. Each note has a number and an arrow to the next note. There is no mailbox number you can shout — you start at the head and follow arrows.
Watch the cursor walk neighbor to neighbor. Then it tries to “jump” to a later node — and fails. Linked lists have no random access; every visit costs a walk.
Walk costs steps. A jump is not free — you still follow arrows.
Types of linked lists
Interviews usually mean a singly linked list: one next pointer per node.
Doubly linked lists also keep a prev. Circular lists hook the tail back to
the head so the chain loops.
Same idea — nodes and pointers — different wiring. Pick the shape that matches the moves you need (walk one way, walk both ways, or wrap around).
Singly is the interview default. Doubly and circular change the arrows.
How it is stored in memory
In TypeScript, head lives on the stack as a reference. Each node object sits
on the heap — scattered sticky notes — and next holds the address of the
following note. Contiguous rows are optional; the arrows are what matter.
Start here. Each step highlights the TypeScript below.
Operations
Think of the list as sticky notes with arrows. Labels below are hops from the head — not random-access indexes. Tap Next on each demo to watch pointers move. For typed snippets and interview patterns, open the Functions tab.
Traverse
Start at the head and follow next until you hit null. Every visit
costs a step — there is no shortcut.
Start at the head. Visit 7.
Search
Looking for a value? Same walk — stop early when you find it, or reach the end empty-handed.
Looking for 9. Head holds 7 — keep walking.
Insert at head
Hook a new car onto the front of the train. Point it at the old head, then move
head to the new node — constant work.
Want 5 at the front. New node’s next must point at the old head.
Insert after a node
Once you stand on a node, splicing a neighbor in is two pointer writes — no sliding a whole row like an array insert.
Insert 5 after the node that holds 3. Stand on that node.
Delete head
Unhook the first car. The second car becomes the new head — one assignment.
Drop the head (7). The next node becomes the new head.
Delete a node
To drop a middle car, point the previous car past it. Keep a prev while you
walk — or use a dummy head so the real head is never special.
Remove the node that holds 3. Keep a handle on the node before it.
Reverse
Flip every arrow in one pass. Keep prev, curr, and a saved
next — classic interview warm-up.
Flip every arrow. Walk once, rewiring next as you go.