Solution: Big (O) of Nested Loop with Subtraction
This review provides a detailed analysis of how to solve the Big (O) of Nested Loop with Subtraction challenge.
We'll cover the following...
Solution #
Press + to interact
int main(){int n = 10;int sum = 0;float pie = 3.14;for (int i=n; i>=1; i-=3){ // O(n/3)cout << pie << endl; // O(n/3)for (int j=n; j>=0; j--){ // O((n/3)*(n+1))sum += 1; // O((n/3)*(n+1))}}cout << sum << endl;}
On line 6 in the outer loop, int i=n;
runs once, i>=1;
gets executed ...
Access this course and 1400+ top-rated courses and projects.