Data Structures
A data structure is a representation plus invariants that make a set of operations efficient. Choose one from the workload—not from a generic ranking of “advantages” and “disadvantages.”
Start with operations
Representation versus interface
A stack or queue is an abstract data type: its contract restricts which element may be removed. It can be implemented by an array, linked nodes, or another container. An array and linked list instead describe storage organization.
Questions to ask
- Which operations dominate, and what are their worst or amortized costs?
- Must references, indexes, or iteration order remain stable after mutation?
- Is capacity bounded, and is allocation allowed during operation?
- How important are cache locality and per-element overhead?
- Are concurrency, persistence, or ownership part of the contract?
Asymptotic costs are necessary but incomplete: two operations can differ substantially in allocation, indirection, and locality.
A workload, not an isolated operation
Suppose a program receives tasks and later processes them in arrival order. Appending them to a dynamic array is linear in total, but repeatedly removing position zero shifts references: quadratic work. A queue with constant-cost endpoint operations keeps the total linear. If instead tasks are repeatedly accessed by their numeric position, a dynamic array may fit better. The linear structures comparison connects these choices to concrete implementations.
The table is an orientation for in-memory structures with stored elements, not a universal guarantee. Hash lookup assumes controlled load and suitable hashing, and still pays to hash and compare keys; collisions can make worst-case lookup linear. Balanced-tree bounds count comparisons, and heap root access assumes a nonempty heap. For interpreting worst-case, expected, and amortized claims, start with time complexity.