Calculating how many iterations to make a list that doubles each iteration, n elements long

501 Views Asked by At

If I have a list of numbers starting with four numbers, the list doubles in size after each iteration, how would I calculate how take to have a list of exactly n elements long? Thanks

2

There are 2 best solutions below

3
On BEST ANSWER

After $n$ iterations, you have $4\cdot 2^n$ elements. If you want to have $N$ elements, $N=4\cdot 2^n, \log_2 N=2+n$

0
On

A sequence is defined by $a_0 = 4$ and $a_n = 2 a_{n-1}$ is given by $$ a_n = 2^{n+2}, \quad n \geq 0. $$ Solve $N = 2^{n+2}$ to get $n = \log_2 N - 2$.