Dynamic Array
Data StructuresavgO(n)worstO(n)spaceO(n)
42
17
88
23
65
9
An array holding 6 values in 8 slots
1 / 33
Starting contents6 values
Operations5 / 40
- 1. insert(50 @ 2)
- 2. delete(@ 0)
- 3. insert(31 @ 6)
- 4. insert(74 @ 1)
- 5. search(23)
How it works
A contiguous block of slots with a size and a capacity. Inserting or deleting in the middle shifts every later element one slot over, and a full array doubles its capacity. That keeps appends at amortised O(1), while edits in the middle cost O(n).
Complexity
- Best
- O(1)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(n)