Giter VIP home page Giter VIP logo

Comments (1)

DockerIsFish avatar DockerIsFish commented on September 10, 2024

LIST의 pop()는 O(1)이지만, pop(0)처럼 첫번째 원소를 삭제하면 삭제 후 모든 원소를 앞으로 이동시키기 때문에 시간 복잡도가 O(n)입니다.

하지만 dequeu 의 popleft()의 시간복잡도는 O(1)입니다. 그 이유는 내부적으로 deque은 double-linked list로 구현되어 있습니다. 그래서 양 끝의 요소의 추가/삭제가 O(1)을 만족하게됩니다.

double-linked list는 블럭을 앞 뒤로 잇는 leftlink와 rightlink가 블록 구조체에 정의되어 있습니다.

이러한 블록이 모여서 dequeobject를 만들며, dequeobject는 전체 오브젝트의 양 끝을 leftindex, rightindex에 따로 저장하고 있습니다.

deque.popleft() 연산 시, 첫번째 블록을 끊어버리고, 연결 노드 인덱스만 갱신하면 되기 때문에 dequeue 연산이 O(1) 만에 가능한 것이다.

출처 : https://velog.io/@bae12/Python-dequeue-%EC%97%B0%EC%82%B0%EC%9D%98-%EC%8B%9C%EA%B0%84-%EB%B3%B5%EC%9E%A1%EB%8F%84-%EB%B9%84%EA%B5%90-list-vs-collections.deque

from coding_test.

Related Issues (7)

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.