Data structures explained: arrays, stacks & queues in English

If you’ve started learning to code, you’ve probably run into the term “data structures” and felt a small wave of dread. It sounds like something out of a textbook, not something you’d casually understand over coffee.

Strip away the jargon, though, and data structures turn out to be one of the more intuitive ideas in programming. A data structure is just a way of organizing information so a computer can work with it efficiently. A filing cabinet, a to-do list, and a checkout line all organize things differently, because each one handles a different job.

This post walks through three of the basics: arrays, stacks, and queues. We’ll keep it in plain English, picking up where our earlier post on what an algorithm actually is left off.

What is a data structure, really?

A data structure is a specific way of storing and organizing data. Done well, it lets you access, change, and process that data without wasting time. Some structures suit ordered lists. Others make adding and removing items fast. Others mainly preserve a specific order of operations.

The structure you pick matters because it affects how fast your program actually runs. Using the wrong one for a job is a bit like organizing a grocery list in a filing cabinet built for legal paperwork. It works, technically, but it’s clunky.

Arrays: the foundation

An array is the simplest of the three. It’s a list of items stored in order, and you can reach each item directly using its position, usually called an index.

Picture a row of numbered lockers down a school hallway. Each locker has its own number. If you know the number, you walk straight to it without checking any of the others along the way.

A few things worth knowing about how arrays behave: items sit in continuous, numbered positions starting at 0 in most languages. If you already know an item’s index, you can jump straight to it. People call this “constant time” access, and it’s about as fast as lookups get. In many languages, arrays also have a fixed size, so you generally need a rough idea of how much space you’ll need before you start.

Arrays are a good fit in a few situations. You need to grab items by position quickly. The order matters and doesn’t shift around much. Or you already have a decent sense of how much data you’re storing. Student grades, coordinates for a game character, the days of the week: all reasonable candidates.

The catch is that inserting or removing something in the middle of an array can get slow. Everything after that point may need to shift over to make room.

Stacks: last in, first out

A stack only lets you add and remove items from one end. The rule is simple: whatever went in last comes out first. People usually shorten this to LIFO.

Think of a stack of plates in a kitchen cabinet. New plates go on top. When you need one, you take it from the top too, never from the bottom. Whichever plate landed there most recently is the one you’ll grab.

Stacks really only need two operations. Push adds a new item to the top. Pop removes whatever’s currently sitting there. You can’t reach into the middle directly; you have to remove anything above the item you want first.

This makes stacks the natural pick whenever you need to reverse an order, backtrack, or keep track of something nested. The undo button in a text editor works this way, unwinding your most recent action first. A browser’s back button does the same thing, sending you to whatever page you visited most recently. Programming languages track function calls the same way too, in what people literally call a call stack. It’s also how you’d check whether the parentheses in a piece of code actually balance out.

Queues: first in, first out

A queue works almost the opposite way. Items go in one end and come out the other. Whatever arrived first, leaves first. People usually shorten this to FIFO.

It’s the same idea as a checkout line at a grocery store. Whoever got there first gets helped first, and everyone behind them waits their turn in the order they showed up.

Queues also rely on two main operations. Enqueue adds a new item to the back. Dequeue removes whatever’s at the front. Unlike a stack, the two ends of a queue do different jobs: new items always join at the back, and only the front end ever lets anything out.

Queues make sense whenever you need to handle things in the exact order they arrived. A shared office printer processes jobs this way. So do customer support tickets, at least when a company handles them properly. Operating systems use queues to schedule processes waiting for resources. Message queues in software systems process data in the order it came in, too.

Arrays vs stacks vs queues: quick comparison

StructureAccess patternBest forReal-world example
ArrayDirect access by indexFast lookups, ordered fixed-size dataNumbered lockers
StackLast in, first outUndo actions, backtracking, nested processesStack of plates
QueueFirst in, first outOrdered task processing, schedulingCheckout line

Why this matters if you’re just starting out

You don’t need to memorize the technical details right away. What matters most is the pattern behind each one. Arrays give you direct, organized access. Stacks reverse order: whatever came in last gets handled first. Queues preserve order: whatever came in first gets handled first.

Once that clicks, you’ll start spotting these patterns outside of code too. Think of how emails pile up in an inbox, or how you work through a to-do list.

These three also set you up for the data structures that come next. Linked lists, trees, and graphs all lean on the same basic ideas: ordering, access, and structure.

Final thoughts

None of this is abstract trivia. Arrays, stacks, and queues are practical tools, and each one suits a different kind of problem. Arrays get you fast, direct access to ordered data. Stacks handle situations where whatever just happened matters most. Queues handle situations where showing up first actually counts for something.

Get comfortable with these three and coding problems start looking a lot less mysterious. It also sets you up nicely for the algorithms our earlier post covers, since those are the things that actually operate on top of these structures.

Leave a Comment

Your email address will not be published. Required fields are marked *