JavaScript/Algorithm
2. 배열과 오브젝트의 성능 평가
code10
2023. 3. 13. 16:29
Udemy - 【한글자막】 JavaScript 알고리즘 & 자료구조 마스터클래스 :: 섹션 3 배열과 오브젝트의 성능 평가
객체의 빅오
Big O of Objects
Insertion - O(1)
Removal - O(1)
Searching - O(N)
Access - O(1)
When you don't need any ordering, objects are an excellent choice!
Big O of Object Methods
Object.keys - O(N)
Object.values - O(N)
Object.entries - O(N)
hasOwnProperty - O(1)
Quiz
질문 1:
오브젝트에 키와 값을 추가하기 위한 빅오는 무엇일까요?
답: O(1)
질문 2:
오브젝트의 키에 접근하기 위한 빅오는 무엇일까요?
답: O(1)
질문 3:
오브젝트의 키를 제거하기 위한 빅오는 무엇일까요?
답: O(1)
빅오 배열 메소드
Big O of Arrays
Insertion - It depends....
Removal - It depends....
Searching - O(N)
Access - O(1)
Let's see what we mean by that!
push, pop 작업이 shift, unshift 작업보다 빠르다. (비어있는 배열일 때 제외)
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 * log N)
- forEach/map/filter/reduce/etc. - O(N)
You don't need to know all this...😵
Limitations of Arrays
Inserting at the beginning is not as easy as we might think! There are more efficient data structures for that!
Quiz
질문 1:
배열 안에 데이터를 삽입하는 빅오는 무엇일까요?
답: O(1)
질문 2:
배열 안에 데이터를 이동하는 빅오는 무엇일까요?
답: O(n)
질문 3:
forEach 함수를 위한 빅오는 무엇일까요?
답: O(n)