Part 1 · Data Structures12 min read

Data Structures: The Containers Behind Fast Apps

Arrays, lists, hash maps, stacks, queues, trees, and graphs explained as practical containers for real apps.

Published: June 24, 2026Last updated: June 26, 2026

Programs handle data: names, prices, appointments, messages, user IDs, documents, files, permissions, and relationships.

A data structure is the container you choose for that data.

The container matters because it decides what is easy, what is slow, and what becomes painful later.

Think about a kitchen. You can throw every spice into one cardboard box, or you can put each spice into a labeled jar. Both choices "store" spices. But when someone asks for salt, the second kitchen wins immediately.

That is data structures.

The practical question

Do not start by asking, "Which data structure should I memorize?"

Ask:

  • Do I need to find one item quickly?
  • Do I need to keep order?
  • Do I need to insert or remove items often?
  • Do I need to represent hierarchy?
  • Do I need to represent many-to-many relationships?

The answer points to the container.

0123
Array
Numbered lockers
Open by position instantly
List
People in a line
Easy middle insertion
keyvalue
Hash Map
Labeled locker
Find by name instantly
Stack
Stack of books
Last in, first out
Queue
Cafe line
First in, first out
Tree
Folder structure
Parent-child hierarchy
Graph
Subway map
Complex relationships

Array and list: lining things up

In practice, "array" and "list" are often mixed together. JavaScript's Array, Python's list, and Java's ArrayList are called lists but are actually dynamic arrays. In CS textbooks, however, "list" usually means a linked list.

The CS distinction

An array is a row of numbered lockers in contiguous memory.

  • Need locker 23? Open it immediately. Index access is O(1).
  • Inserting in the middle shifts everything after it.
  • Size is often fixed.

A linked list is people holding hands in a line.

  • Inserting in the middle only changes two hand-holds. Insert/delete is O(1) once you find the spot, but finding the spot is O(n).
  • Finding the 23rd person requires counting from the front.
  • Size grows freely.
ViewArrayLinked list
Memory layoutContiguous blockScattered nodes + pointers
Index accessO(1), open directlyO(n), count from front
Middle insert/deleteO(n), must shiftO(1), relink neighbors
SizeUsually fixedGrows freely
Memory useCompact and predictableExtra pointers per node

What languages actually give you

LanguageNameWhat it really is
JavaScriptArrayDynamic array
PythonlistDynamic array
JavaArrayListDynamic array
JavaLinkedListLinked list
C++std::vectorDynamic array
C++std::listLinked list

When to use which

Use an array / dynamic array when

  • You need fast access by index.
  • You mostly append or remove from the end.
  • You want contiguous, predictable memory.
  • Examples: search results, product lists, table rows, sorted data.

Use a linked list when

  • You insert and delete in the middle very often.
  • You iterate more than you look up by position.
  • The size changes unpredictably.
  • Examples: queue/stack implementations, undo history, linked memory blocks.

In everyday app work, you often meet arrays as:

  • A list of products.
  • Search results.
  • Messages in a chat.
  • Rows in a table.
  • Steps in a workflow.

Hash map: labeled lockers

A hash map is one of the most useful structures in practical programming.

Imagine lockers with labels instead of numbers:

  • user_123
  • cart_total
  • appointment_2026_06_25
  • feature_flag_checkout

If you know the label, the value can be found almost immediately.

Hash maps show up everywhere:

  • Finding a user by ID.
  • Caching an API response.
  • Counting how many times each word appears.
  • Storing settings by name.
  • Grouping records by status.

Stack and queue: pile or line

A stack is a pile of books. The last book placed on top is the first one you remove.

This is called LIFO: last in, first out.

Stacks appear in:

  • Browser back buttons.
  • Undo history.
  • Function calls.
  • Nested parsing.

A queue is a cafe line. The first person who arrives is the first person served.

This is called FIFO: first in, first out.

Queues appear in:

  • Email sending.
  • Background jobs.
  • Print jobs.
  • Message processing.
  • AI tasks waiting to be processed.

Tree and graph: branches and networks

A tree is a hierarchy.

Folders inside folders. Comments with replies. A company org chart. A menu with submenus.

Trees are useful when each item has a parent and children.

A graph is a network.

Social friends. Subway stations. Web pages linking to other pages. Products related to other products.

Graphs are useful when relationships are not simply top-down. One thing can connect to many things in many directions.

Quick comparison

StructureEveryday metaphorGood atWeak atCommon app use
ArrayNumbered lockersFast access by positionMiddle insert/deleteOrdered items, table rows
ListPeople in a lineFlexible growthDirect position accessChanging sequences
Hash mapLabeled lockersFast lookup by keyGuaranteed orderUser lookup, cache, settings
StackPile of booksLast item firstMiddle accessUndo, back button
QueueCafe lineFirst item firstMiddle accessJobs, messages, task processing
TreeFolder structureHierarchyCross-linksMenus, comments, files
GraphSubway mapComplex connectionsSearch costSocial, routing, recommendations

How this appears in AI-built apps

AI often writes code that is correct for the sample data in the prompt. That sample data is usually tiny.

Watch for:

  1. Arrays used everywhere Using arrays for fast search, deduplication, or membership checks when a different structure would be better.

  2. Repeated array.find() Doing linear scans through a list to find data by ID, instead of using Map or an object dictionary.

  3. Deduplication with lists Calling includes() repeatedly to check for existing values, when Set would be simpler and faster.

  4. Deeply nested relationship data Storing user → posts → comments → likes as one deeply nested object, making updates and lookups complex.

  5. Unnormalized state Copying the same data to multiple places so that updating one copy leaves stale data elsewhere.

  6. Treating tree structures like lists Scanning all items linearly for hierarchical data like categories, menus, org charts, or comment threads.

  7. Treating graph problems like trees Recursing through friend relationships, recommendations, dependencies, or workflows without a visited set.

  8. Using array.shift() where a queue is needed Processing job queues, notifications, or background jobs with array.shift(), which gets slower as data grows.

  9. Recursion without stack/queue awareness Handling deep trees or workflows only with recursion, risking stack overflow.

  10. Sorting the whole list for top-k Sorting the entire list every time just to find the most important task, latest event, or top score item.

  11. Plain object cache without LRU structure Caching data without size limits, expiration, or eviction policies.

  12. No index-like structure Recomputing search, filter, groupBy, and count from the original list every time.

  13. Direct mutation of nested objects Mutating deep objects directly, which confuses React state detection, undo/redo, and diff calculation.

  14. One giant object for large data Managing a single massive object where partial updates become hard and small changes trigger full clones or re-renders.

  15. Data access pattern mismatched with structure Using only basic lists and objects without considering read/write ratio, ordering, or lookup speed.

Frequently asked questions

What is a data structure?

A data structure is the shape you give to information so your program can store, find, change, and connect it efficiently.

Array vs list: which should I use?

Use an array or dynamic array when you need fast access by position and mostly append or remove from the end. Use a linked list only when frequent insertions or deletions in the middle are a real bottleneck.

When should I use a hash map?

Use a hash map when you need to look up values by a unique key almost instantly. Examples include user profiles by ID, cached API responses, and settings by name.

What is the difference between a stack and a queue?

A stack is last-in-first-out, like a pile of books. A queue is first-in-first-out, like a line at a cafe.

When should I use a tree instead of a list?

Use a tree when your data has a hierarchy with parents and children, such as folders, comments with replies, or organization charts.

The takeaway

Data structures are not academic trivia. They are the shape of your product’s memory.

Pick the right container, and the code feels obvious. Pick the wrong one, and every feature becomes a fight.

About the Author

Jaehee Song

Jaehee Song

Enterprise data platform architect with 20+ years of experience building data systems for Fortune 500 companies. AI development educator who has taught vibe coding and AI development to hundreds of students. Founder of Seattle Partners, helping Korean technology startups navigate the US market.

Author of the AI Development Guide