I am learning the dynamic stack implementation using 2 ways (incremental and double)
When stack is full, then only it will grow 2x of capacity
stack->storage = realloc(stack, stack->capacity * 2 * sizeof(int));
stack->capacity *= 2;
So the for $n$ elements, the stack will be grown $\log_2{n}$ times (times the realloc is called). And the copy operation on old elements only happens on the growth.
The calculation is not clear to me (Page 97, Data Structures and Algorithm made easy)
Based on the geometric progression, shouldnt it $𝑂(2^𝑛)$?
Here I am assuming for every
realloc
, we will get a different memory location.