Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to talk about how deque is implemented in Python #114

Open
bharatagarwal opened this issue Sep 13, 2023 · 2 comments
Open

Request to talk about how deque is implemented in Python #114

bharatagarwal opened this issue Sep 13, 2023 · 2 comments

Comments

@bharatagarwal
Copy link
Contributor

I've noticed a significant performance in the hot potato problem between using the naive implementation of Queue v/s the solution that uses collections.deque.

The naive implementation of Deque has similar performance issues, with insert and remove from left/rear requiring the whole array to move over.

CPython has an implementation using double linked lists, which could be worth talking about once the "Lists" section has been covered.

@bharatagarwal
Copy link
Contributor Author

If doubly linked lists are out of scope for the book, might be worthwhile to add a note at the end of the hot potato problem, mentioning the performance difference and sharing the link to the CPython deque implementation as an exercise for the reader.

@bharatagarwal bharatagarwal changed the title Talk about how deque is implemented in Python Request to talk about how deque is implemented in Python Sep 13, 2023
@robot-dreams
Copy link
Collaborator

Good idea! book/queues/implementation.md mentions the performance implications, but mentioning that collections.deque uses a doubly-linked list and linking to an implementation could be helpful. (BTW It could also be interesting to mention that in CPython the elements of the linked list are blocks, rather than single elements—it cuts down on the cache misses a bit.)

Please feel free to open a PR adding a sentence / link wherever you think is appropriate, maybe the end of book/deques/implementation.md?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants