Comments (2)
상호 교환하여 사용할 수 없습니다. 따라서 그것들을 비교하는 것은 거의 의미가 없습니다.
추가와 반복은 큰 차이를 만들지 않으며, 제거하고 가장 중요한 것은 조회가 차이를 만든다.
Set 클래스 의 요소 에는 액세스 가능한 인덱스가 없습니다
Set class is an Array class complement, useful in those scenarios where we need to store a collection on which to apply basic addition, Deletion, checking and iteration operations.
-
요소추가
Array.push() set.add() -
컬렉션의 수정을 위한 iterating(반복)
array(for), set(for of) -
컬렉션에서 요소 제거
array(for, .splice) < set(for of, .delete) -
색인 찾기
arr.indexOf( item ) < set.has( item );
설계 디자인에 따라 결과가 다르게 나오는 것같은데.... 제거, 조회할 때에는 set 이 빠른것이 결론
from algorithm.
그냥 논리적인 추측을 해보자면,
추가
set의 경우 추가할 때 중복 처리를 어떤 방식으로든 처리할 것이고
array는 중복 처리를 고려할 필요 없이 메모리에 순차적으로 쌓아놓기만 하면 됨
반복문으로 탐색
set은 배열처럼 단순히 메모리에 순차적으로 들어가는 게 형태가 아니기 때문에 탐색도 오래걸릴 수 밖에 없음. 즉 기본적으로 메모리 용량을 1개 더 사용한다는거지
array는
0->1->2->3->4 이렇게 반복하면 되지만
Set은
[k1->v0]->[k1->v1]->... 이런식으로 반복할 것임
확실한건 value를 찾기 위해선 key도 필요하다는 점
제거
set은 기본적으로 key-value 형태와 유사한(즉, 해시맵과 유사한) 탐색구조를 가지고 있기 때문에 한 개의 요소 탐색/삭제에 대해 월등한 퍼포먼스를 보여줌
from algorithm.
Related Issues (13)
- CountingElements.FrogRiverOne 문제 도와주세요. HOT 2
- 404 page not found error
- 코드 개선하기
- 10월 이벤트
- 이미지 저장소 HOT 1
- binaryGap 코드리뷰 HOT 3
- CyclicRotation HOT 2
- 스터디 참여 문의드립니다 HOT 2
- counting_elements/max_counters 풀어주세요. HOT 2
- 1차 면담 HOT 18
- JS 코드 관련 질문 올립니다 HOT 3
- 스터디 참여 신청 알림 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algorithm.