deque are implemented a little smarter than just doubly-linked lists. They're a doubly-linked list of blocks of Python objects, where the left and right sides may be incomplete blocks.

The Big-O cost of accessing in the middle is still O(n), but it has a constant divisor (implementation dependent, CPython 3.5 allocates blocks that can store 64 objects). So if your deque has 1000 members, accessing in the middle still involves only around 7-8 "linked list-style" traversals, not 500-some. If the deque is smallish (65 to 128 elements, depending on how the empty slots align with the head and tail blocks), then lookup of any element is equal cost.

Answer from ShadowRanger on Stack Overflow
๐ŸŒ
Real Python
realpython.com โ€บ python-deque
Python's deque: Implement Efficient Queues and Stacks โ€“ Real Python
January 12, 2026 - This process takes longer to complete, and the append operation passes from being O(1) to O(n). Consider the following performance tests for appending items to the left end of a sequence, deque vs list: ... from collections import deque from ...
Discussions

python - Deque (time complexity) - Stack Overflow
What is the time complexity for accessing deque[0], deque[somewhere in the middle], and deque[-1]? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to make dequeue o(1) operation rather than o(n)?
Nvm. I just found out that deque from python has constant dequeue time complexity by using a stack More on reddit.com
๐ŸŒ r/leetcode
11
3
April 30, 2021
Big O Cheat Sheet: the time complexities of operations Python's data structures
Good for people getting into programming in general. I only have one remark: I wouldn't qualify O(n) as "Slow !" since it's still practically fast for low values of n and has the elegance of scaling linearly, which is one of the best scenarios available in the vast amount of cases a programmer will face. More on reddit.com
๐ŸŒ r/Python
28
209
April 16, 2024
What is Python's list.append() method WORST Time Complexity? It can't be O(1), right?
I've read on Stackoverflow that in Python Array doubles in size when run of space It's actually not double, but it does increase proportional to the list size (IIRC it's about 12%, though there's some variance at smaller sizes). This does result in the same asymptotics though, so I'll assume doubling in the following description for simplicity. So basically it has to copy all addresses log(n) times. Not quite. Suppose we're appending n items to an empty vector. We will indeed do log(n) resizes, so you might think "Well, resizes are O(n), so log(n) resizes is n log(n) operations, which if we amortize over the n appends we did means n log(n)/n, or log(n) per append". However, there's a flaw in this analysis: we do not copy "all addresses" each of those times. Ie. the copies are not O(n). Sure, the last copy we do will involve copying n items, but the one before it only copied n/2, and so on. So we actually do 1 + 2 + 4 + ... + n copies, which sums to 2n-1. Divide that by n and you get ~2 operations per append - a constant. I assume since it copies addresses, not information We are indeed only copying the pointer, but this doesn't really matter for the complexity analysis. Even if it was copying a large structure, that'd only increase the time by a constant factor. Does that mean that O(1) is the average time complexity? It's the amortized worst case complexity (ie. what happens over a large number of operations). While any one operation can indeed end up doing O(n) operations, there's an important distinction that over a large number of operations, you are guaranteed to only be O(1), which is a distinction just talking about average case wouldn't capture. More on reddit.com
๐ŸŒ r/learnpython
11
3
October 26, 2022
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ TimeComplexity
TimeComplexity - Python Wiki
A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ends are accessible, but even looking at the middle is slow, and adding to or removing from the middle is slower still. See dict -- the implementation is intentionally very similar. As seen in the source code the complexities for set difference s-t or s.difference(t) (set_difference()) and in-place set difference s.difference_update(t) (set_difference_update_internal()) are different!
๐ŸŒ
DEV Community
dev.to โ€บ wnleao โ€บ python-deque-vs-list-time-comparison-5ch4
Python deque vs list: a time comparison - DEV Community
April 10, 2022 - Deques are a generalization of ... efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ deque-in-python
Deque in Python - GeeksforGeeks
A deque stands for Double-Ended Queue. It is a type of data structure that allows to add and remove elements from both ends efficiently. Allows fast insertion and deletion from both the front and rear ends. Works as both a queue (FIFO) and a stack (LIFO). Useful in scheduling, sliding window problems and real-time data processing.
Published ย  May 29, 2026
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ deque
Python | Deque | Codecademy
April 10, 2025 - It provides a versatile data structure ... inserting or removing elements at the beginning, deques provide O(1) time complexity for these operations on both ends....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ deque-implementation-in-python
Deque Implementation in Python - GeeksforGeeks
July 23, 2025 - If there are multiple items, it moves the front pointer to the next node and updates the prev pointer of the new front to None. Time Complexity : All operations (append, insert, remove) are O(1), since adding or removing elements only requires ...
Find elsewhere
๐ŸŒ
Pythoncomplexity
pythoncomplexity.com โ€บ stdlib โ€บ deque
Deque - Python Big-O: Time & Space Complexity
from collections import deque import time # List - O(n) popleft (must shift all elements) lst = list(range(1000000)) start = time.time() for _ in range(1000): lst.pop(0) # O(n) list_time = time.time() - start # Deque - O(1) popleft dq = deque(range(1000000)) start = time.time() for _ in range(1000): dq.popleft() # O(1) deque_time = time.time() - start # deque is much faster for queue operations
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ deque-python
Python Deque: Example, Implementation & Methods (with code)
March 15, 2023 - Deque offers O(1) time complexity for append and pop operations from both ends of the container, it is favored over a list when we need faster append and pop operations from both ends of the container.
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ using-deque-in-python-python-queues-and-stacks-made-easy
Using Deque in Python | Python Queues and Stacks Guide
March 12, 2024 - Unlike lists, deque is designed to allow efficient append and pop operations from both ends, with a time complexity of O(1). This makes it a much more efficient alternative for implementing queues and stacks.
๐ŸŒ
Python Central
pythoncentral.io โ€บ understanding-pythons-deque
Understanding Python's deque | Python Central
February 11, 2025 - A Python dequeis a linear data structure that supports fast appends and pops from both ends. It is implemented as a doubly linked list, which allows for O(1) time complexity for append and pop operations at both the front and the back.
๐ŸŒ
Reddit
reddit.com โ€บ r/leetcode โ€บ how to make dequeue o(1) operation rather than o(n)?
r/leetcode on Reddit: How to make dequeue o(1) operation rather than o(n)?
April 30, 2021 -

I would like to use queues for BFS problems but the thing is if I use a queue as an array I would have to remove from the beginning and shift everything down. Is there any other way to do iterative BFS without having such performance heavy operations? Iโ€™m using python fyi

๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ linked-lists-stacks-and-queues-in-python โ€บ lessons โ€บ understanding-and-implementing-queues-exploring-core-concepts-python-implementation-and-time-complexity
Understanding and Implementing Queues: Exploring Core ...
In order to make smart decisions about data structures, it's important to be mindful of their time and space complexities. In the case of a Queue implemented using the collections.deque, the time complexity for both the enqueue (adding an element at the end of the Queue) and dequeue (removing ...
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ deque
Python deque - Complete Guide
April 2, 2025 - A deque (pronounced "deck") is a double-ended queue from Python's collections module that supports efficient append and pop operations from both ends. It provides O(1) time complexity for these operations compared to O(n) for lists. This guide covers deque creation, operations, performance ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ deque-in-python
Deque in Python
June 26, 2020 - The Deque is basically a generalization of stack and queue structure, where it is initialized from left to right. It uses the list object to create a deque.It provides O(1) time complexity for popping and appending.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - The official Python Wiki details the complexities of various operations for list and deque. ... In a list, operations like pop(0) (remove and return the first element) and insert(0, v) (add an element to the head) have O(n) time complexity.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ time-complexities
Python Big O: the time complexities of different data structures in Python - Python Morsels
April 16, 2024 - For inexpensive operations involving the least-recently added item (the beginning of a list), we'd need a queue-like structure. That's what Python's collections.deque data structure is for. >>> from collections import deque >>> queue = deque([2, 1, 3, 4]) Here are the time complexities of common deque operations:
๐ŸŒ
Dataquest
dataquest.io โ€บ home โ€บ blog โ€บ python deque function: a better choice for queues and stacks
Python Deque Function: A Better Choice for Queues and Stacks โ€“ Dataquest
April 7, 2025 - That is where the deque() function (short for double-ended queue, pronounced like "deck") from the collections module can be a much better choice when you need to implement queues and stacks in Python. They offer efficient (O(1) time complexity) addition and removal of elements from both ends, making them particularly handy for the typical operations of queues and stacks.
๐ŸŒ
OpenGenus
iq.opengenus.org โ€บ deque-python
Deque in Python
March 20, 2020 - To begin using Deque in your python program use the code given below. import collections de = collections.deque([1,2,3]) Deque requires O(1) time to perform the operations of append and pop. Whereas, a list requires O(N) complexity. For reference a machine takes 1s to perform 10^6 operations.