Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions big_o_exercise/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +29,9 @@ function logUpTo(n) {
}
}

Time Complexity: O(n)
Space Complexity: O(1)

// 2.

function logAtMost10(n) {
Expand All @@ -37,6 +40,9 @@ function logAtMost10(n) {
}
}

Time Complexity: O(1)
Space Complexity: O(1)

// 3.

function logAtLeast10(n) {
Expand All @@ -45,6 +51,9 @@ function logAtLeast10(n) {
}
}

Time Complexity: O(n)
Space Complexity: O(1)

// 4.

function onlyElementsAtEvenIndex(array) {
Expand All @@ -57,6 +66,9 @@ function onlyElementsAtEvenIndex(array) {
return newArray;
}

Time Complexity: O(n)
Space Complexity: O(n)

// 5.

function subtotals(array) {
Expand All @@ -70,4 +82,7 @@ function subtotals(array) {
}
return subtotalArray;
}

Time Complexity: O(n^2)
Space Complexity: O(n)
```