Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Parts 1&2 for Big O exercises #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
36 changes: 26 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(log(n))
7. `O(1000 * n * log(n) + n)` --> O(nlog(n))
8. `O(2^n + n^2)` --> O(n^2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is O(2^n), since exponential growth is faster than quadratic growth. We didn't cover this in class though, so I wouldn't sweat this one too much!

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) - I want to say O(n) because you'd have to store array.length/2 values in the new array...

// 5.

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

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

```