var x = 0.01; for (var i = 0; i <= 50; i++) { System.out.printf("%2d %2.16f%n", i, x); x = 4*x - 3*x*x; }and got an answer of 1.3084580315967430. This value is probably nowhere near the actual value, since it is performing iterative computation with limited precision.
So the number of stars printed is:
1+2+2+3+3+3+3+4+4+4+4+4+4+4+4+5+5+5+5+5+5+5+5+5+5+5+5+5+5+5+5+6+6+6...where there are $n$ terms in total. We can compute $T$ exactly! Note:
$T(n) = \sum_{i=1}^n \log_2 i + 1$
Now we need to figure out how to get the $\Theta$ in here. To do this, we need to find upper and lower bounds.
The function $T$ is bounded above by $\lambda n. \sum_{i=1}^n 2 \log_2 i$, or $\lambda n. 2n \log n$. It is bounded below by $\lambda n. 0.5n \log n$ because half of that summation is, well, less that the full summation. Since we have $2n \log n$ as an upper bound and $0.5n \log n$ as a lower bound, we have $\boxed{\Theta(n \log n)}$
There was a typo in the original assignmentThe assignment when first given had the outer loop copy-pasted from the previous problem, namely:
for (var i = n; n >= 1; n /= 2) {In this case, we have the same situation as the previous problem, in which $i$ never changes, so the inner loop always has $n$ steps, with $\boxed{W(n) \in \Theta(n \log n)}$ .
BigInteger
or BigDecimal
, the numbers themselves are collections and the number of bits [or digits] in the number becomes part of the problem input size.” Because the question referred to numbers of unbounded size, the “size of the input” is the number of bits (or digits) of the input numbers.
$n$ | True input size (Digits) | $2^n$ | True output size (Digits) |
---|---|---|---|
5 | 1 | 32 | 2 digits |
9 | 1 | 512 | 3 digits |
20 | 2 | 1048576 | 7 digits |
40 | 2 | 1099511627776 | 13 digits |
70 | 2 | 22 digits | |
120 | 3 | 37 digits | |
1000 | 4 | 302 digits | |
9999 | 4 | 3010 digits |
$n$ | True input size (Bits) | $2^n$ | True output size (Bits) |
---|---|---|---|
$n$ | $\log n$ | $2^n$ | $n = 2^{\log n}$ |