Linked list

The notes

What is a linked list?

A linear collection of elements called nodes, which are not stored contiguously in memory but are linked together by pointers.

  • The head points to the first node
  • Each node holds data and a pointer to the next node
  • The last node points to null

Anatomy of a node

  • Data: stores the element value
  • Pointer (or reference): holds the memory address of the next node

Key features

  • Dynamic size: grows and shrinks as needed
  • Efficient insertion/deletion: can add or remove nodes quickly
  • Sequential access: elements are accessed one by one
  • No random access: cannot directly access elements by index

Types of linked lists

  • Singly linked list: each node points forward to the next
  • Doubly linked list: nodes point both forward and backward (prev and next)
  • Circular linked list: the last node's pointer points back to the first node

Data structures deck

  1. 1. Linear vs non-linear
  2. 2. Arrays
  3. 3. Hashmaps
  4. 4. Stacks
  5. 5. Queue
  6. 6. Linked list
  7. 7. Binary tree
  8. 8. BST
  9. 9. Graphs
  10. 10. Heaps

Watch the lesson

Data structures, Lesson 5, from 0:46: Why Linked Lists?