Linked Lists

Nodes linked by pointers — insert and delete without shifting a contiguous block.

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.

Four nodes · follow next, no jump
Readinghead → 7

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).

How linked lists are classified
FocusLinked list

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.

Declare → allocate nodes → link
StatusPress Next to declare head

Start here. Each step highlights the TypeScript below.

Step 1 of 4

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.

Walk the chain
Statuswalk

Start at the head. Visit 7.

Step 1 of 4

Looking for a value? Same walk — stop early when you find it, or reach the end empty-handed.

Find a value
Statussearch

Looking for 9. Head holds 7 — keep walking.

Step 1 of 3

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.

Add at the front
Statusinsert head

Want 5 at the front. New node’s next must point at the old head.

Step 1 of 3

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.

Splice after a node
Statusfind spot

Insert 5 after the node that holds 3. Stand on that node.

Step 1 of 3

Delete head

Unhook the first car. The second car becomes the new head — one assignment.

Remove the head
Statusdelete head

Drop the head (7). The next node becomes the new head.

Step 1 of 2

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.

Bypass a middle node
Statusfind

Remove the node that holds 3. Keep a handle on the node before it.

Step 1 of 3

Reverse

Flip every arrow in one pass. Keep prev, curr, and a saved next — classic interview warm-up.

Flip every arrow
Statusreverse

Flip every arrow. Walk once, rewiring next as you go.

Step 1 of 4