Skip to content

Commit a170795

Browse files
author
Wakidur Rahaman
committed
sumRule
1 parent 5d8b148 commit a170795

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/big-O-complexities/big-o-rule.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,31 @@ function coefficientRuleOneTwo(limit: number) {
7373

7474
/**
7575
* 2. Sum Rule
76+
* Imagine a master algorithm that involves two other algorithms.
77+
* The Big-O notation of that master algorithm is simply the sum of the other two Big-O notations.
78+
*/
79+
80+
function sumRule(boxes: string[], items: number[]) {
81+
// For boxes iteration
82+
boxes.forEach(element => {
83+
// O(n)
84+
console.log(element);
85+
});
86+
87+
// For items iteration
88+
items.forEach(element => {
89+
// O(n)
90+
console.log(element);
91+
});
92+
}
93+
94+
/**
95+
* BIG O Calculation
96+
* O(n + n)
97+
* O( a + b )
98+
*/
99+
100+
/**
101+
* Product Rule
102+
*
76103
*/

0 commit comments

Comments
 (0)