← Back to Home
L
ALGO / Linked List
Contact us
Tags
Linked ListData Structure
Algorithm

What is a Linked List?

A Linked List is a linear data structure where elements called nodes are stored in sequence. Each node contains data and a pointer (or link) to the next node in the sequence. Unlike arrays, linked lists do not store elements in contiguous memory locations.

The first node is called the head. The last node points to null to indicate the end of the list.

When to Use Linked List

01

Dynamic Size

When you don't know the total size upfront — lists grow and shrink at runtime without reallocation

02

Frequent Insertions/Deletions

When you need to add or remove elements often at arbitrary positions — O(1) at head vs O(n) for arrays

03

No Random Access Needed

When sequential traversal is acceptable and you rarely need O(1) access by index

04

Real-time Data Streams

When processing data as it arrives — buffers, streams, task queues

Consider an Array Instead When:

You need fast random access by index • You have a known, fixed size • Memory is constrained (pointer overhead) • You need cache-friendly access patterns

Node Structure

DATA
→
  • ›Data: Stores the actual value (can be any data type)
  • ›Next Pointer: Points to the next node in the sequence
  • ›Head: First node of the list
  • ›Null: Last node points to null to mark end

Types of Linked Lists

Singly Linked ListMost Common

Each node has only a next pointer. Traversal is one-directional: from head to tail.

10
→
20
→
30
→
null
Use cases:Stack implementation, breadth-first traversal queue, undo functionality
Doubly Linked ListBidirectional

Each node has next and prev pointers. Can traverse both forward and backward.

←
10
20
→
←
30
null
Use cases:Browser forward/back navigation, music playlist, text editor undo/redo
Circular Linked ListLoop

Last node points back to the head (or first node), forming a circle. No null at the end.

10
→
20
→
30
→
↩back to head
Use cases:Round-robin scheduling, multiplayer game turns, circular buffer

Common Operations

OperationDescriptionTime Complexity
Insert at HeadAdd new node at beginningO(1)
Insert at TailAdd new node at endO(n)
Delete by ValueRemove first node with valueO(n)
SearchFind node by valueO(n)
ReverseReverse node orderO(n)

Linked List vs Array

AspectLinked ListArray
MemoryDynamic, non-contiguousFixed size, contiguous
AccessSequential only O(n)Random access O(1)
Insert at HeadO(1)O(n) — shift elements
Delete at HeadO(1)O(n) — shift elements
Memory OverheadExtra for pointersNo extra overhead