...

/

Solution Review: Big (O) of Nested Loop with Subtraction

Solution Review: 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.

Solution

Press + to interact
Rust 1.40.0
fn main(){
let n = 10;
let mut sum = 0;
let pie = 3.14;
for i in (1..n).rev().step_by(3){
println!("{}", pie);
for j in (0..n).rev(){
sum += 1;
}
}
println!("{}",sum);
}

See the following table for a detailed line-by-line analysis of the calculation of time complexity.

Statement
Number of Executions
let n = 10;
1
let mut sum = 0;
1
let pie = 3.14;
1
for i in (1..n).rev().step_by(3)
n3\frac{n}{3}
println!("{}", pie);
n3\frac{n}{3}
for j in (0..n).rev()
n3n\frac{n}{3} * n
...
Access this course and 1400+ top-rated courses and projects.