Thirty One Copies
An unbounded array starts at size = 0, limit = 1. Each add writes at index size, increments size, and then, if size == limit, doubles limit and copies all size elements into a fresh array.
| add # | size after | limit after | elements copied |
|---|---|---|---|
| 1 | 1 | 2 | 1 |
| 2 | 2 | 4 | 2 |
| 3 | 3 | 4 | 0 |
| 4 | 4 | 8 | 4 |
| 5, 6, 7 | 5, 6, 7 | 8 | 0 |
After 17 add calls, how many element copies have happened in total?
Sign in to answer questions and track your progress
Sign In