Question: In Java Do Number One Please Sum . Find sigma k = 1 n ( 5 k + 3 ) using a for() loop. Use
In Java Do Number One Please
- Sum. Find sigma k = 1 n ( 5 k + 3 ) using a for() loop. Use System.nanoTime() to time the loop. Now use the closed formula 5 n ( n + 1 ) 2 + 3 n, i.e. one Java statement. Use System.nanoTime() to time the formula.
- Write timings for n= 1e7 (ten million), 1e8 (hundred million), 1e9 (billion).
- long begin = System.nanoTime();
- ... // sigma
- long end = System.nanoTime();
- long timeSum = end - begin; // time in nanoseconds
- Is sigma linear time O(n)?
- Is the formula constant time O(1)?
- Write timings for n= 1e7 (ten million), 1e8 (hundred million), 1e9 (billion).
Note: k = 1 10 ( 5 k + 3 ) = (5*1 + 3) + (5*2 + 3) + (5*3 + 3) + ... + (5*10 + 3) = 8 + 13 + 18 + ... + 53 = 305
5 n ( n + 1 ) 2 + 3 n =
Type or paste question here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
