Big O
- Big O shows the time and space complexity of an algorithm. (Performance efficiency)
- Doesn't care about precision, just general trend
- Relationship between input size and time
- O(1) - constant (input doesn't affect)
- O(n) - linear (grows propotrionally)
- O(n^2) - quadratic
- O(log n)
- O(n log n)
Big O of objects #
- Insertion - O(1)
- Removal - O(1)
- Searching - O(n)
- Access - O(1)
- Object.keys - O(n)
- Object.values - O(n)
- Object.entries - O(n)
- hasOwnProperty - O(1)
Big O of arrays #
- Insertion - O(1) to the end; O(n) to the beginning(unshift); it needs to reindex each element
- Removal - O(1) from the end; O(n) from the beginning (shift)
- Searching - O(n)
- Access - O(1)
- push - O(1)
- pop - O(1)
- shift - O(n)
- unshift - O(n)
- concat - O(n)
- slice - O(n)
- splice - O(n)
- sort - O(n log n)