Linked Lists — ELI5
Imagine a treasure hunt where each clue card has two things: a prize and directions to the next clue. You start at the first card, grab the prize, follow the directions, find the next card, and keep going until a card says “The End.”
That is a linked list. Each card is called a node, and it holds two pieces of information:
- The data — the actual value stored (like a number, a name, or anything).
- A pointer — directions to the next node.
The first node is called the head. The last node points to nothing (like a card that says “stop here”).
This is different from a regular Python list, which is more like a row of numbered lockers. With lockers, you can jump straight to locker number 50. With a linked list, you have to start at the first node and follow the chain — there is no shortcut to the middle.
So why use a linked list? Because adding or removing something at the beginning is super fast. With lockers, if you want to insert something at the start, you have to shift everything over by one. With a linked list, you just create a new card, point it to the old first card, and you are done.
Python does not have a built-in linked list type, but you can build one with simple classes. And Python’s collections.deque is actually powered by a similar idea under the hood.
One thing to remember: Linked lists are great when you need to add or remove items frequently at the ends, but they are slow when you need to jump to a specific position. Choose the right tool for the job.
See Also
- Python Backtracking Algorithms How computers solve puzzles by trying every path, backing up when stuck, and never giving up until they find the answer.
- Python Big O Complexity Analysis Why some programs finish in a blink while others take forever — explained with pizza delivery and toy cleanup.
- Python Binary Search Implementation Find anything in a sorted list insanely fast using the same trick you already use with dictionaries and phone books.
- Python Dynamic Programming The clever trick of remembering answers you already figured out so you never solve the same puzzle twice.
- Python Graph Algorithms How computers navigate maps, friendships, and connections using dots and lines — explained without any math.