Back

Linked List Data Structure

Introduction to Linked List

What is a Linked List?

A Linked List is a linear data structure where elements (nodes) are not stored at contiguous memory locations. Each node contains a value and a pointer (reference) to the next node in the sequence. Unlike arrays, linked lists can easily grow and shrink in size, making them ideal for dynamic memory management.

Key Characteristics

  • Each node contains data and a pointer to the next node.
  • Nodes are not stored in contiguous memory.
  • Dynamic size: can grow or shrink during execution.
  • Efficient insertion and deletion from anywhere in the list.
  • Can be used to implement complex data structures like stacks, queues, graphs, and polynomials.

Real-World Analogy

Imagine a treasure hunt where each clue (node) gives you the location of the next clue. You can't skip ahead; you must follow the chain one by one. Similarly, in a linked list, you must follow each node's pointer to reach the next node.

Another analogy: Think of a train where each coach (node) is connected to the next. You can add or remove coaches easily, but to reach a specific coach, you must pass through all previous ones.

Visualization

10Node
20Node
30Node
40Node
NULLEnd

Each box is a node. The arrow shows the pointer to the next node. The last node points to NULL.

Linked List Illustration