diff --git a/big_o_exercise/readme.md b/big_o_exercise/readme.md index c732b1d..ea29222 100644 --- a/big_o_exercise/readme.md +++ b/big_o_exercise/readme.md @@ -4,16 +4,16 @@ Simplify the following big O expressions as much as possible: -1. `O(n + 10)` -2. `O(100 * n)` -3. `O(25)` -4. `O(n^2 + n^3)` -5. `O(n + n + n + n)` -6. `O(1000 * log(n) + n)` -7. `O(1000 * n * log(n) + n)` -8. `O(2^n + n^2)` -9. `O(5 + 3 + 1)` -10. `O(n + n^(1/2) + n^2 + n * log(n)^10)` +1. `O(n + 10)` --> `O(n)` +2. `O(100 * n)` --> `O(n)` +3. `O(25)` --> `O(1)` +4. `O(n^2 + n^3)` --> `O(n^3)` +5. `O(n + n + n + n)` --> `O(n)` +6. `O(1000 * log(n) + n)` --> `O(n)` +7. `O(1000 * n * log(n) + n)` --> `O(n * log(n))` +8. `O(2^n + n^2)` --> `O(2^n)` +9. `O(5 + 3 + 1)` --> `O(1)` +10. `O(n + n^(1/2) + n^2 + n * log(n)^10)` --> `O(n^2)` ### Part 2 @@ -29,6 +29,9 @@ function logUpTo(n) { } } +Time Complexity: O(n) +Space Complexity: O(1) + // 2. function logAtMost10(n) { @@ -37,6 +40,9 @@ function logAtMost10(n) { } } +Time Complexity: O(1) +Space Complexity: O(1) + // 3. function logAtLeast10(n) { @@ -45,6 +51,9 @@ function logAtLeast10(n) { } } +Time Complexity: O(n) +Space Complexity: O(1) + // 4. function onlyElementsAtEvenIndex(array) { @@ -57,6 +66,9 @@ function onlyElementsAtEvenIndex(array) { return newArray; } +Time Complexity: O(n) +Space Complexity: O(n) + // 5. function subtotals(array) { @@ -70,4 +82,7 @@ function subtotals(array) { } return subtotalArray; } + +Time Complexity: O(n^2) +Space Complexity: O(n) ```