- Published on
Understanding Data Structures Through Real-Life Examples: A Beginner’s Guide
- Authors
- Name
- Pulathisi Kariyawasam
- @RandhanaK

When you're just getting into programming, data structures might sound like a dry and complicated topic. But the truth is, they are all around us — even in the apps you use every day. In this post, we’ll explore the most common data structures by relating them to things you already understand.
Arrays – Like a Row of Lockers
Think of an array like a row of school lockers. Each locker is numbered, and you can quickly open any one of them if you know the number. In programming, arrays are used to store items in a specific order, and they’re great when you want fast access to items using their position (or index).
Example:
In a photo gallery app, images are stored in an array. When you swipe through the photos, the app loads the next image using its position in the array.
Linked Lists – Like a Treasure Hunt
A linked list is like a treasure hunt where each clue leads to the next. Each item (or node) in a linked list contains the data and a link to the next item. This structure is useful when you want to add or remove items without shifting everything around.
Example:
Music streaming apps often use linked lists to manage playlists. Songs are played one after the other, and you can add or remove songs easily without affecting the whole playlist.
Stacks – Like Plates in a Pile
A stack follows the Last In, First Out (LIFO) rule — the last item you put on the stack is the first one you take off. It’s like stacking plates: you add to the top and remove from the top.
Example:
Web browsers use stacks to manage the back button. Each time you visit a page, it’s pushed onto the stack. When you hit "back," the browser pops the top page off and shows the previous one.
Queues – Like a Line at the Bank
A queue follows the First In, First Out (FIFO) rule — the first person in line is the first to be served. It’s fair and orderly.
Example:
When you send documents to print, they go into a queue. The printer handles them one by one, in the order they were sent.
Trees – Like a Family Tree
Trees are used to represent data with a branching structure. Each item is called a node, and it can have child nodes, just like a family tree.
Example:
Your computer's file system is a tree. You have folders (nodes) inside other folders, with files (leaves) inside them.
Graphs – Like Social Networks
Graphs connect items through relationships. Each item is a node, and the connection between them is called an edge. These are perfect for modeling complex relationships.
Example:
Social media platforms use graphs to represent users and their connections. Your friends, followers, and mutual friends are all part of a big graph.
Why It Matters
Understanding data structures helps you write better, more efficient code. It also gives you insight into how software you use every day is built and how it works under the hood.
Whether you’re building your first app or preparing for technical interviews, knowing these basics will give you a strong foundation.