A data structure is not good or bad in general. It is cheap for some operations and expensive for others, and the only honest way to choose one is to start from the operations your system actually performs.

That sounds obvious until you watch how choices are usually made: by habit, by familiarity, or by a single impressive number quoted for one operation. "Pick the structure with the best worst-case time" feels rigorous, but it answers a question no real system asks. Real systems ask several questions, at different frequencies, at a particular size — and the bill is dominated by the frequent ones.

Start with the operation profile

Before you pick anything, list the questions the system must answer, and how often each question is asked. That list is the operation profile, and it governs the choice the way a brief governs a building. A structure that answers the frequent question slowly will be slow, no matter how elegant it looks. A structure that answers a rare question slowly may be perfectly fine.

Consider a parcel company's customer portal, where a customer types a parcel number and expects the parcel's status. The senior engineer who owns the portal's design record begins that record not with a structure, but with the list of questions the portal must answer. The frequent operation is lookup by exact parcel number: one key, one record, millions of times a day. The rare operation is listing all parcels in parcel-number order, perhaps once a night for a report.

A hash table answers the frequent operation in roughly constant time: it hashes the key, jumps to a slot, and returns the record. Listing in order requires sorting the keys, which is slow — but it happens rarely, so its cost is affordable. A sorted list answers the nightly listing beautifully, and answers the frequent lookup by scanning or by binary search, which is slower per lookup than a hash, though still modest.

The choice turns on frequency. The portal's bill is dominated by lookups, so the hash table wins for the portal, even though the sorted list is the prettier structure on paper. Now change the profile: make the ordered report the product, run hourly, over the whole set. The answer changes with it. Nothing about either structure changed. The question changed.

The same method, a different answer

Work the method on a second service in the same company: the depot sorting board. Here the frequent operations are different. Take the next parcel for a route, in route order. Insert a late parcel into its correct position. Remove a parcel that has been rerouted.

An array keeps parcels in order and gives instant access by position, but inserting into the middle forces every later parcel to shift — a cost that grows with the board. A linked list inserts cheaply once you stand at the right node, but finding that node requires walking from the start. A balanced tree holds order and inserts, deletes, and finds in logarithmic time, at the price of more memory and more complex code.

For two hundred parcels, any of the three works and the simplest wins. For two hundred thousand with constant insertions, the array's shifting becomes the day's work. The profile — size, frequency, and which operations dominate — decides, differently at different sizes. The useful question is never "which structure is best?" without the rest of the sentence: "for which profile, at which size?"

Four operations cover most profiles

Most profiles can be named in four terms, and naming them first does most of the work.

Lookup by exact key: hash tables and indexes shine. Lookup by order or range — all records between two values, or the smallest ten: sorted structures and trees shine. Insertion and deletion in the middle: linked structures and trees shine; arrays pay a shifting cost. Iteration over everything in order: arrays and sorted structures shine; hash tables, whose order hashing scrambles, do not.

Name the profile in those terms, then state the size at which your choice stops being true. A choice with a stated breaking point is an engineering decision. A choice without one is a hope.

Keep the structure behind the interface

One more discipline belongs at the start: separate the interface from the implementation. The portal needs "find by parcel number" and "list in order." It does not need to know, at the level of the feature, whether lookup is a hash table today. Hide the structure behind that interface, and you can change it when the profile changes — when the nightly report becomes hourly, when a thousand records become a million — without rewriting the feature. Engineers who weld a feature to one structure pay for every later change twice: once in the structure, and once in every caller that assumed it.

Finally, make the profile cheap to keep honest. Write it on the design itself, where the next engineer cannot miss it: operations, frequencies, sizes, and the date the numbers were last checked. A profile left in a meeting notebook decays within a quarter, because products change their questions constantly — a search box gains a filter, a report gains a live mode. When the profile lives beside the structure it justifies, a changed question is visibly a changed assumption. The date matters: a profile without one invites trust long after it has expired, while a dated profile asks, in writing, to be re-measured.

There is no fastest structure in general, only a fastest structure for a given profile. A hash table beats a sorted list on exact lookup and loses on ordered listing. A tree beats an array on middle insertion and loses on memory and simplicity. State the profile, state the size, name the breaking point, and hide the choice behind the interface. Do that, and the structure follows the question — which is where it belonged all along.

Experience it, don’t just read about it

Choosing a structure by its operation profile, not by a single quoted speed is Concept 1 of Data Structures & Algorithms in Practice (Course No. 210), from Cognosco Learning, a learning company powered by AI. The course builds the wider judgment beyond this distinction — Complexity Budgets, Hash Tables That Stay Fast, and Trees That Hold Order — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.

Try a Free PreviewAll Signature CoursesThe Corporate License

Navigate your own course.

← All Insights

© 2026 Cognosco Learning. All rights reserved.