-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigO-notation.txt
72 lines (48 loc) · 1.41 KB
/
BigO-notation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## **Step One: Simplifying Expressions**
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)) ***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 * log(n)^10) ***O(n^2)
## **Step Two: Calculating Time Complexity**
1. O(n)
2. O(n)
3. O(1)
4. O(n^2) ***O(n)
5. O(n^2)
6. O(n)
## **Part 3 - short answer**
Answer the following questions
1. True or false: n^2 + n is O(n^2).
True
2. True or false: n^2 * n is O(n^3).
True
3. True or false: n^2 + n is O(n).
False
4. What’s the time complexity of the .indexOf array method?
O(n)
5. What’s the time complexity of the .includes array method?
O(n)
6. What’s the time complexity of the .forEach array method?
O(n)
7. What’s the time complexity of the .sort array method?
O(n log(n))
8. What’s the time complexity of the .unshift array method?
O(n)
9. What’s the time complexity of the .push array method?
O(1)
10. What’s the time complexity of the .splice array method?
O(n)
11. What’s the time complexity of the .pop array method?
O(1)
12. What’s the time complexity of the Object.keys() function?
O(n)
Bonus. What’s the space complexity of the Object.keys() function?
O(n)