...
/Solution: Big (O) of Nested Loop With Addition
Solution: Big (O) of Nested Loop With Addition
This review provides a detailed analysis of the time complexity of the Nested Loop with Addition problem!
We'll cover the following...
We'll cover the following...
Solution #
On line 6 in the outer loop, var i=1; runs once, i<n; gets executed times and i+=3 executed times. In the inner loop, var j=1; gets executed times in total. j<n; executes times and j+=2 gets executed times. Study the following table for a more detailed line-by-line analysis of the calculation of time complexity.
const n = 10 |
|
var sum = 0 |
|
const pie = 3.14 |
|
var i=1 |
|
i<n |