-
Notifications
You must be signed in to change notification settings - Fork 140
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
Big O exercise #26
base: master
Are you sure you want to change the base?
Big O exercise #26
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,25 @@ | |
Simplify the following big O expressions as much as possible: | ||
|
||
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(n * log(n)) | ||
8. `O(2^n + n^2)` | ||
O(n^2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
9. `O(5 + 3 + 1)` | ||
O(1) | ||
10. `O(n + n^(1/2) + n^2 + n * log(n)^10)` | ||
O(n^2) | ||
|
||
### Part 2 | ||
|
||
|
@@ -28,6 +38,8 @@ function logUpTo(n) { | |
console.log(i); | ||
} | ||
} | ||
Time: O(n) | ||
Space: O(1) | ||
|
||
// 2. | ||
|
||
|
@@ -36,6 +48,8 @@ function logAtMost10(n) { | |
console.log(i); | ||
} | ||
} | ||
Time: O(n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double check your time complexity here. What's the largest number of operations that will be performed? |
||
Space: 0(1) | ||
|
||
// 3. | ||
|
||
|
@@ -44,6 +58,8 @@ function logAtLeast10(n) { | |
console.log(i); | ||
} | ||
} | ||
Time: O(n) | ||
Space: 0(1) | ||
|
||
// 4. | ||
|
||
|
@@ -56,6 +72,8 @@ function onlyElementsAtEvenIndex(array) { | |
} | ||
return newArray; | ||
} | ||
Time: O(n) | ||
Space: O(n) | ||
|
||
// 5. | ||
|
||
|
@@ -70,4 +88,7 @@ function subtotals(array) { | |
} | ||
return subtotalArray; | ||
} | ||
Time: 0(n^2) | ||
Space: O(n) | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double check this one - which grows faster,
log(n)
orn
?