Skip to content

Tech in 2 Minutes

Data Structures for Beginners: Arrays, Lists, Stacks, Queues and More

A beginner-friendly guide to data structures: arrays, linked lists, stacks, queues, hash maps, trees and graphs, with everyday analogies and when to use each.

Data Structures for Beginners: Arrays, Lists, Stacks, Queues and More
In this article
  1. What Is a Data Structure?
  2. Why Data Structures Matter
  3. 1. Arrays
  4. 2. Linked Lists
  5. 3. Stacks
  6. 4. Queues
  7. 5. Hash Maps (Dictionaries)
  8. 6. Trees
  9. 7. Graphs
  10. How to Choose the Right Data Structure
  11. A Quick Word on Big O
  12. Common Beginner Mistakes
  13. Data Structures FAQ
  14. Key Takeaway
  15. Mini Cheat Sheet

Every app stores and works with data: a list of products, a chat history, a user's settings, a map of roads. How that data is organised decides how fast the app can find, add or remove things.

That organisation is called a data structure, and it is one of the first things every programmer learns.

What Is a Data Structure?

A data structure is a way of organising and storing data in a computer so it can be used efficiently.

Different structures are good at different jobs. Some are fast at looking things up, some are fast at adding new items, and some are great at showing relationships.

In simple words: a data structure is the container you choose for your data, like choosing between a bookshelf, a filing cabinet or a stack of plates.

Why Data Structures Matter

Imagine finding one customer among 10 million:

  • With a plain list, you may have to check customers one by one.
  • With a hash map keyed by email, you can find them almost instantly.

Same data, different structure, massive difference in speed. Data structures work hand in hand with algorithms, the step-by-step methods that process the data. Read Algorithm Explained for New Programmers for the other half of the picture.

1. Arrays

An array stores items in order, one after another, each with a numbered position called an index (usually starting at 0).

fruits = ["apple", "banana", "mango"]
fruits[1]   # "banana"
  • Good at: reading any item instantly by its index.
  • Not so good at: inserting or deleting in the middle, because other items must shift.
  • Everyday analogy: numbered seats in a cinema row.

2. Linked Lists

A linked list is a chain of items where each item points to the next one.

  • Good at: adding or removing items without shifting everything else.
  • Not so good at: jumping to the 500th item; you must follow the chain from the start.
  • Everyday analogy: a treasure hunt where each clue tells you where the next clue is.

3. Stacks

A stack follows Last In, First Out (LIFO). You add to the top (push) and remove from the top (pop).

  • Used for: the undo button, the browser back button, and keeping track of function calls in a program.
  • Everyday analogy: a stack of plates. You take the one you put on last.

4. Queues

A queue follows First In, First Out (FIFO). Items join at the back and leave from the front.

  • Used for: print jobs, background job queues (sending emails, processing uploads), and handling requests in order.
  • Everyday analogy: a line at a ticket counter.

5. Hash Maps (Dictionaries)

A hash map stores key-value pairs. You look up a value using its key.

user = {
  "name": "Asha",
  "email": "asha@example.com",
  "plan": "pro"
}
user["plan"]   # "pro"
  • Good at: very fast lookup, insert and delete by key.
  • Used for: caches, user sessions, counting things, settings, JSON objects.
  • Everyday analogy: a dictionary. You go straight to the word instead of reading from page one.

Hash maps are called dictionaries in Python, objects or Maps in JavaScript, and associative arrays in PHP.

6. Trees

A tree stores data in a hierarchy: one root at the top, with branches to child nodes below.

  • Used for: folders on your computer, website menus, the HTML structure of a page (the DOM), and database indexes.
  • A special kind, the binary search tree, keeps data sorted so searches are fast.
  • Everyday analogy: a family tree or a company org chart.

7. Graphs

A graph is a set of points (nodes) connected by lines (edges). Unlike trees, any node can connect to any other.

  • Used for: maps and route-finding, social networks (who follows whom), recommendation systems and network routing.
  • Everyday analogy: a metro map with stations and lines.

How to Choose the Right Data Structure

Ask what your code does most often:

  • Need items in order and access by position? Use an array.
  • Need to look things up by a name or ID? Use a hash map.
  • Need "last in, first out"? Use a stack.
  • Need "first in, first out"? Use a queue.
  • Have parent-child relationships? Use a tree.
  • Have many-to-many connections? Use a graph.

A Quick Word on Big O

Programmers describe speed using Big O notation, which shows how work grows as data grows:

  • O(1): constant time. Same speed with 10 items or 10 million. Example: hash map lookup.
  • O(n): grows with the data. Example: searching an unsorted list.
  • O(log n): grows very slowly. Example: searching a sorted tree.

You don't need to master Big O on day one, but recognising these three will help you understand most discussions.

Common Beginner Mistakes

  • Using an array for everything, then searching it again and again in loops.
  • Ignoring built-in structures. Every modern language already provides arrays, maps, sets and queues. Use them before writing your own.
  • Optimising too early. For small amounts of data, the simplest structure is usually fine.

Data Structures FAQ

Do I need data structures for web development?

Yes, every day. JSON objects are hash maps, lists of products are arrays, and job queues are queues. Knowing them helps you write faster, cleaner code.

What is the difference between an array and a list?

The terms vary by language. Generally, an array is a fixed block of ordered items, while a "list" may be an array that can grow, or a linked list.

Which data structures should I learn first?

Start with arrays and hash maps. They cover most everyday programming. Then learn stacks, queues and trees.


Key Takeaway

A data structure is how you organise data so your program can use it efficiently. Pick the structure that matches what your code does most: arrays for order, hash maps for lookups, stacks and queues for processing order, trees for hierarchy, and graphs for connections.

Mini Cheat Sheet

  • Array: ordered, fast access by index
  • Linked list: chain, easy insert and delete
  • Stack: last in, first out
  • Queue: first in, first out
  • Hash map: fast lookup by key
  • Tree: hierarchy
  • Graph: network of connections

Try it: Need sample records to practise with? Generate realistic test data as JSON with our free fake data generator, and learn more about the format in JSON Explained in Under 2 Minutes.

Join the conversation

What do you think?

Write a comment

Comments are reviewed before they appear.

No comments yet. Be the first to share a thought.

More stories

All stories