AI Features

Solution: Big (O) of Nested Loop With Multiplication

This review provides a detailed analysis of the different ways to solve the Big (O) of Nested Loop with Multiplication Quiz.

We'll cover the following...

Solution

Node.js
// Initializations
const n = 10;
const pie = 3.14;
let sum = 0;
var i = 1;
while (i < n) {
console.log(pie);
for (var j = 0; j < i; j++) {
sum = sum + 1;
}
i *= 2;
}
console.log(sum)

Time Complexity

The outer loop here runs log(n)log(n) times. In the first iteration of the outer loop, the body of the inner loop runs once. In the second iteration, it runs twice, and so on. The number of executions of the body of the inner loop increases in powers of 2. So, if kk ...

Ask