What's the benefit of deque comparing with array?(Python)


  • 0
    W

    Python, just use the common array to get AC. New Pythoner, don't understand much.

    Just want to know why we use deque instead of array? Easier? Or faster?


  • 1
    1. Python doesn't have arrays, or at least they're not called that. You mean lists.
    2. Deques are faster for certain operations. In particular, popping from the front is O(1) instead of O(n). Check https://wiki.python.org/moin/TimeComplexity.

  • 0
    W

    Thank you! And another question: what is the difference between O(n) and O(k)? I didn't see it ever(learned a little C). Thank you again!


  • 0

    Sorry, I don't quite understand your question. The difference is that one uses n and the other uses k. Do you mean what the difference between n and k is? That depends on the context. If you mean on that page I showed, the page says:

    Generally, 'n' is the number of elements currently in the container. 'k' is either the value of a parameter or the number of elements in the parameter.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.