Dynamic array
An array that, when full, moves itself into a bigger one by copying its elements. That way you can add without knowing the size in advance.
Example
With capacity 10, adding the 11th element moves it to 20 slots. Python's list and Java's ArrayList work this way.
Test yourself: Dynamic array
Dynamic lists
What problem does a dynamic array solve?
With a fixed array of 100, element 101 doesn't fit; with one of 1 million for 100 items, 999,900 slots are left over. The dynamic one grows as needed.
Dynamic lists
A list starts with capacity 10 and factor 2. After adding 25 elements, its capacity is ___.
At the 11th it goes from 10 to 20, at the 21st from 20 to 40. With 25 elements there are 15 free slots.
Dynamic lists
How is a dynamic list different from a fixed array?
Both read position 500 in 1 step. The difference shows when adding element 101 to one of 100: the array can't, the list moves to 200.
0/3
â–¶ Play