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
39 changes: 39 additions & 0 deletions big_o_exercise/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,35 @@
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))
Copy link
Contributor

Choose a reason for hiding this comment

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

check this one again - which grows faster, log(n) or n?


7. `O(1000 * n * log(n) + n)`
O(n*log(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 cover this in class so I wouldn't sweat this one too much.

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 @@ -28,6 +48,10 @@ function logUpTo(n) {
console.log(i);
}
}
Time: O(n)
Space: O(1)



// 2.

Expand All @@ -36,6 +60,9 @@ function logAtMost10(n) {
console.log(i);
}
}
Time: O(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 your time complexity here.

Space: O(1)


// 3.

Expand All @@ -44,6 +71,10 @@ function logAtLeast10(n) {
console.log(i);
}
}
Time: O(n)
Space: O(1)



// 4.

Expand All @@ -56,6 +87,10 @@ function onlyElementsAtEvenIndex(array) {
}
return newArray;
}
Time: O(n)
Space: O(n)



// 5.

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

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

```