B2.2.1

Compare static and dynamic data structures

Have a fixed size determined at compile time — size cannot change during execution.

1 min read193 words

Static Data Structures

Have a fixed size determined at compile time — size cannot change during execution.

SpeedFaster access due to contiguous memory allocation
MemoryPredictable usage; fixed size
OverheadNo runtime allocation cost

Disadvantages:

  • Inflexible size — cannot grow or shrink
  • Potential memory waste if overallocated
  • Cannot adapt to changing data needs

Dynamic Data Structures

Can grow or shrink during execution — memory is allocated at runtime.

SizeFlexible; adapts to runtime requirements
MemoryAllocates only what’s needed
EaseEasier to work with in practice

Disadvantages:

  • Slightly slower due to resizing
  • Runtime allocation overhead
  • More complex implementation

Comparison Table

FeatureStaticDynamic
SizeFixed at compile timeChanges at runtime
SpeedFaster accessSlightly slower
MemoryPredictable, may waste spaceEfficient, may fragment
FlexibilityInflexibleAdaptable
ImplementationSimplerMore complex
Example (Python)tuplelist, dict, set

Start typing to search all published objectives.