| ss | s | |
| s |
What is a data structure?
A data structure is a specific way of organizing and storing data in computer memory so that programs can access and modify it efficiently. The structure refers not just to the data values themselves, but to the explicit relationships between them.
Every program uses data structures. A primitive variable is the simplest form, while arrays, trees, and hash tables organize collections of elements to optimize particular operations. The choice of structure directly determines computational speed and memory consumption.
Why data structures matter
Selecting an appropriate data structure is the difference between scalable software and systems that grind to a halt under load. The performance characteristics of fundamental operations vary dramatically depending on the structure chosen.
Consider finding an entry among 1,000,000 items:
- An unsorted list requires inspecting items one by one in O(n) linear time, needing up to 1,000,000 comparisons.
- A binary search tree or sorted array with binary search locates the item in at most 20 comparisons in O(log n) logarithmic time.
At scale, this difference is the boundary between an application that responds instantly and one that hangs indefinitely.
How to evaluate and choose
Selecting the right structure depends on answering three practical questions:
- Which operations occur most frequently: reading, inserting, deleting, or searching?
- What are the strict latency constraints of those frequent operations?
- How much memory overhead can be tolerated for storing pointers or hash buckets?