DEV Community

Sreekar Reddy
Sreekar Reddy

Posted on • Originally published at sreekarreddy.com

πŸ”— Linked Lists Explained Like You're 5

Treasure hunt clues pointing to next

Day 35 of 149

πŸ‘‰ Full deep-dive with code examples


The Treasure Hunt

Each clue tells you where the next clue is:

Clue 1: "Go to the park" β†’
Clue 2: "Look under the bench" β†’
Clue 3: "Check the fountain" β†’
Treasure! 🎁
Enter fullscreen mode Exit fullscreen mode

Each clue POINTS to the next one!

Linked lists work the same way!


Arrays vs Linked Lists

Array: Line of lockers next to each other

[A][B][C][D][E]
Enter fullscreen mode Exit fullscreen mode

Want to insert between B and C? You often end up moving a bunch of items!

Linked List: Each item points to the next

A β†’ B β†’ C β†’ D β†’ E β†’ null
Enter fullscreen mode Exit fullscreen mode

Insert between B and C? Just change pointers!


The Trade-off

Operation Array Linked List
Access by index Fast! Slower (you often walk through)
Insert/delete Slow (shift elements) Fast!

When to Use

  • Lots of insertions/deletions? β†’ Linked list
  • Random access by index? β†’ Array

In One Sentence

Linked lists store data in nodes where each node points to the next, making insertions easy but direct access slow.


πŸ”— Enjoying these? Follow for daily ELI5 explanations!

Making complex tech concepts simple, one day at a time.

Top comments (0)