This is my question, and I managed to get the answer for part a, but for part b I am not very sure of my answer to part b.
In a recent court case, a judge quoted the city for contempt and ordered a fine of $ 2 on the first day. Each subsequent day, until the city followed the order of the judges, the finish was squared (i.e. the result was as follows: $ 2, $ 4, $ 16, $ 256, $ 65536, ...). a. What will be day N day? b. How many days will it take to get to D dollars (Big-Oh answer)?
Ans a: 2 ^ (2 ^ n-1)
For answer b, I made the following program to find the big Oh.
for (int i = 0; i < n - 1; i++) {
result = 2 * result;
}
printf("%d\t", result);
for (int j = 0; j < result; j++) {
res = 2 * res ;
}
printf("%d\n", res);
I calculated the big Oh of the first cycle, which will be the sum of n And since the second cycle runs 2 ^ n-1 times the first cycle, its big Oh is 2 ^ n and adding them both they become (2 ^ n) + n