From b0560bca402350af736f75a1a357867671ba2567 Mon Sep 17 00:00:00 2001 From: Michelle Huynh Date: Mon, 31 Jul 2017 15:30:48 -0700 Subject: [PATCH 1/2] testing a change to commit --- big_o_exercise/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/big_o_exercise/readme.md b/big_o_exercise/readme.md index c732b1d..2eeea7a 100644 --- a/big_o_exercise/readme.md +++ b/big_o_exercise/readme.md @@ -4,7 +4,7 @@ Simplify the following big O expressions as much as possible: -1. `O(n + 10)` +1. `O(n + 10)` Testing a change to commit 2. `O(100 * n)` 3. `O(25)` 4. `O(n^2 + n^3)` From 5aa17cfb57da85c14a46c1c88bb4a81af0b8db0f Mon Sep 17 00:00:00 2001 From: Michelle Huynh Date: Mon, 31 Jul 2017 16:05:21 -0700 Subject: [PATCH 2/2] finished part 1 and 2 of big o exercises --- big_o_exercise/readme.md | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/big_o_exercise/readme.md b/big_o_exercise/readme.md index 2eeea7a..97cd95b 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)` Testing a change to commit -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(log(n)) +7. `O(1000 * n * log(n) + n)` --> O(nlog(n)) +8. `O(2^n + n^2)` --> O(n^2) +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) - I want to say O(n) because you'd have to store array.length/2 values in the new array... + // 5. function subtotals(array) { @@ -70,4 +82,8 @@ function subtotals(array) { } return subtotalArray; } + +// Time Complexity: O(n^2) +// Space Complexity: O(n) + ```