https://cs.slides.com/colt_steele/built-in-data-structures-25
When to use objects, don’t need order
Need fast access O(1) / insertion O(1) / removal O(1) in constant time.
Searching O(N) in linear time
Big O of Object Methods
Object.key O(N)
Object.values O(N)
Object.entries O(N)
hasOwnProperty O(1)
Big O of Array
Searching O(N)
Access O(1)
Insertion depends on where to put. It has to re-index every single element in the array
Same goes to removal.
It is good to beware that it is not as efficient as adding in removing at the end.
so push and pop always faster than shift and unshift.
Built in Array Method
Big O of Array Operations
Push O(1)
Pop O(1)
Shift O(N)
Unshift O(N)
Concat O(N)
Slice O(N)
Splice O(N)
Sort O(N* logN)
forEach/mat/filter/reduce/etc… O(N)
'Javascript > Algorithms' 카테고리의 다른 글
Searching Algorithms (0) | 2020.12.23 |
---|---|
Recursion (0) | 2020.12.20 |
Problem Solving Patterns (0) | 2020.12.09 |
Problem Solving Approach (0) | 2020.12.08 |
Introducing Big O (0) | 2020.12.03 |