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

first commit - Big O exercise #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 33 additions & 2 deletions big_o_exercise/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@

Simplify the following big O expressions as much as possible:

1. `O(n + 10)`
1. `O(n + 10)`
// O(n)
2. `O(100 * n)`
3. `O(25)`
// O(n)
3. `O(1)`
// O(n)
4. `O(n^2 + n^3)`
// O(n^3)
5. `O(n + n + n + n)`
// O(n)
6. `O(1000 * log(n) + n)`
// log(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

double check this one - what grows faster, log(n) or n?

7. `O(1000 * n * log(n) + n)`
// nlog(n)
8. `O(2^n + 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.

2^n grows faster than n^2, but we didn't talk about this in class so I wouldn't sweat it.

// 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

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


time: O(n)
space: O(1)



// 2.

function logAtMost10(n) {
Expand All @@ -37,6 +53,10 @@ function logAtMost10(n) {
}
}

time: O(1)
space: O(1)


// 3.

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

time: O(n)
space: O(1)

// 4.

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

time: O(n)
space: O(n)


// 5.

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

time: O(n^2)
space: O(n)

```
13 changes: 0 additions & 13 deletions readme.md

This file was deleted.