A trade-off is a practical compromise: improving one property means accepting a disadvantage somewhere else. Choosing well means balancing the costs that matter for your situation rather than chasing perfection. section 1.6 section 1.7
A dynamic-array compromise
Suppose a collection usually holds 100 elements but occasionally grows to 10,000. Reserving space for the peak avoids resizing but wastes memory; allocating space as needed saves memory but periodically requires moving elements. A dynamic array hides this resizing from the developer, but pays for it occasionally through slower operations. section 5.2 section 5.3
Use the trade-off to guide practical choices:
- Choose a static array when the size is known or changes only slightly; predictable capacity can avoid unnecessary resizing. section 5.3
- Choose a dynamic array when the size varies greatly; flexibility and reduced wasted memory can justify occasional resizing costs. section 5.3
- For queues, linked lists favor flexible size and simpler code, while arrays can provide better performance when capacity can be pre-allocated. section 9.9
- Keeping an array sorted can make some operations faster, but requires adapting insertion and deletion and accepting their associated costs. section 3.0
The goal is usually not to find the theoretically perfect option. It is to avoid choices that create unacceptable performance, memory, reliability, or security problems, then select a near-optimal alternative for the context. section 1.7 section 1.6




