diff --git a/Chapter09/Cargo.toml b/Chapter09/Cargo.toml index 39b5f1b..6af6578 100644 --- a/Chapter09/Cargo.toml +++ b/Chapter09/Cargo.toml @@ -50,3 +50,11 @@ path = "performance_polynomial1.rs" [[bin]] name = "performance_polynomial2" path = "performance_polynomial2.rs" + +[[bin]] +name = "performance_polynomial3" +path = "performance_polynomial3.rs" + +[[bin]] +name = "performance_polynomial4" +path = "performance_polynomial4.rs" diff --git a/Chapter09/performance_polynomial3.rs b/Chapter09/performance_polynomial3.rs new file mode 100644 index 0000000..40dedfc --- /dev/null +++ b/Chapter09/performance_polynomial3.rs @@ -0,0 +1,25 @@ +fn a(n: u64) { + //Is this O(n)? + for _ in 0..n { + b(n) + } +} + +fn b(n: u64) { + //Is this O(n)? + for _ in 0..n { + c(n) + } +} + +fn c(n: u64) { + //This is O(n)? + for _ in 0..n { + let _ = 1 + 1; + } +} + +fn main() { + //What time complexity is this? + a(1000) +} diff --git a/Chapter09/performance_polynomial4.rs b/Chapter09/performance_polynomial4.rs new file mode 100644 index 0000000..f79c691 --- /dev/null +++ b/Chapter09/performance_polynomial4.rs @@ -0,0 +1,2 @@ +fn main() { +}