File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
+ * Big-O is important for analyzing and comparing the efficiencies of algorithms.
2
3
* Big-O Rule
3
4
*
4
5
* 1. Coefficient rule
@@ -98,7 +99,7 @@ function sumRule(boxes: string[], items: number[]) {
98
99
*/
99
100
100
101
/**
101
- * Product Rule
102
+ * 3. Product Rule
102
103
* The product rule simply states how Big-Os can be multiplied.
103
104
*/
104
105
@@ -129,3 +130,20 @@ function productRuleTwo(n: number) {
129
130
* O(n^2)
130
131
* O(n^2) is called Quadratic Time
131
132
*/
133
+
134
+ /**
135
+ * 4. Polynomial Rule
136
+ * If f(n) is a polynomial of degree k, then f(n) is O(nˆk).
137
+ * The following code block has only one for loop with quadratic time complexity f(n) = nˆ2 because line 4 runs n*n iterations
138
+ */
139
+
140
+ function polynomialRule ( n : number ) {
141
+ let count = 0 ;
142
+ for ( let i = 0 ; i < n * n ; i ++ ) {
143
+ count += 1 ;
144
+ }
145
+ return count ;
146
+ }
147
+
148
+ // O(n^2)
149
+ // O(n^n)
You can’t perform that action at this time.
0 commit comments