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

  1. 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)?

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!