Search⌘ K
AI Features

Solution: Big (O) of Nested Loop With Multiplication

Explore how nested loops with logarithmic and exponential iteration patterns affect algorithm time complexity. Understand the geometric series sum involved in inner loops and how to derive Big O notation for efficient JavaScript code analysis.

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 ...