-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigO.js
More file actions
52 lines (46 loc) · 940 Bytes
/
Copy pathBigO.js
File metadata and controls
52 lines (46 loc) · 940 Bytes
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
//BigO notations and examples
// O(n) Proportional
((n)=> {
for(let i=0; i<n; i++){
console.log(i)
}
for(let j=0; j<n; j++){
console.log(j)
}
})(n)
// O(n^2) Loop within a Loop
((n)=>{
for(let i=0; i<x; i++){
for(let j=0; j<x; j++){
console.log(i, j)
}
}
})(n)
//Different Terms of input
// O(a+b)
((a, b)=>{
for(let i=0; i<a;i++){
console.log(i)
}
for(let j=0; j<b; j++){
console.log(j)
}
})(a,b)
// O(a*b)
((a, b=>{
for(let i=0;i<a;i++){
for(let j=0; j<b; j++){
console.log(a,b)
}
}
}))(a,b)
// O(1) :Number of operations will always be one, most
// efficient BigO same as constant Time
((n)=>{
return n+n
})(n)
//last BigO O(log n) Divide and conquer
//BigO of Arrays
//.pop(), .push(), .indexOf( ) are O(1)
//.shift(), .unshift(), .splice() are O(n)
//resources: BigOcheatsheet.com