Git Product home page Git Product logo

Comments (2)

eyabc avatar eyabc commented on August 15, 2024

출처

상호 교환하여 사용할 수 없습니다. 따라서 그것들을 비교하는 것은 거의 의미가 없습니다.
추가와 반복은 큰 차이를 만들지 않으며, 제거하고 가장 중요한 것은 조회가 차이를 만든다.
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.

  1. 요소추가
    Array.push() set.add()

  2. 컬렉션의 수정을 위한 iterating(반복)
    array(for), set(for of)

  3. 컬렉션에서 요소 제거
    array(for, .splice) < set(for of, .delete)

  4. 색인 찾기
    arr.indexOf( item ) < set.has( item );

설계 디자인에 따라 결과가 다르게 나오는 것같은데.... 제거, 조회할 때에는 set 이 빠른것이 결론

from algorithm.

JunilHwang avatar JunilHwang commented on August 15, 2024

그냥 논리적인 추측을 해보자면,

추가

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.