Foundations & Complexity

data structure

A data structure is a way of organizing data so the operations you care about become easy. Think of how you store things at home. A shopping list on a single strip of paper is great for reading top to bottom but awful for inserting an item in the middle. A spice rack with alphabetized jars lets you grab oregano instantly but is annoying to keep sorted. A stack of plates lets you take from the top in a flash but never from the bottom. None of these is 'best' in the abstract — each is shaped to make some actions cheap, accepting that others become expensive.

In computing it is the same. An array gives you instant access to the i-th item but slow insertion in the middle. A linked list flips that trade. A hash table makes 'is this here?' nearly instant but loses any sense of order. A binary search tree keeps things sorted while still allowing fast lookup. A data structure is the concrete layout of the bytes plus the set of operations defined on them; it is the partner of an algorithm, because an algorithm's speed often depends entirely on the structure it runs over.

This is why the two halves of this subject — algorithms and data structures — are always taught together. Picking the right structure is frequently the difference between code that finishes in a blink and code that grinds to a halt. The discipline is: name the operations you will do most often, then choose the structure that makes those operations cheap (often O(1) or O(log n)) while keeping the rest tolerable. The reasoning tool we use to compare them is asymptotic analysis.

A data structure is the concrete layout; an abstract data type is the promised behavior independent of layout. The same ADT can be backed by different data structures.

Also called
数据结构資料結構