1:46, how is deque's popleft method O(1)? deque like list is index traversed right? so it too needs to shift the elements in case I need to print deque(3) after the popleft method?
a double ended queue is just a singly linked list with references to the head and tail right? also someone might want to use deque for stack instead of list to have worst case o(1) append time, where in list it can be o(n)
it has to be doubly-linked I believe, otherwise you can't add/remove from both ends. I believe cpython's deque is implemented as doubly-linked chunks of buffers instead of individually linked items
as covered in the video -- it has different performance characteristics than a standard list and is useful for implementing things where random access is unimportant but access at ends is (queues are a big example, lru another)
1:46, how is deque's popleft method O(1)? deque like list is index traversed right? so it too needs to shift the elements in case I need to print deque(3) after the popleft method?
a deque is like a linked list of blocks -- indexing is worst case O(N) but at the edges it's fast
@@anthonywritescode thanks
a double ended queue is just a singly linked list with references to the head and tail right?
also someone might want to use deque for stack instead of list to have worst case o(1) append time, where in list it can be o(n)
it has to be doubly-linked I believe, otherwise you can't add/remove from both ends. I believe cpython's deque is implemented as doubly-linked chunks of buffers instead of individually linked items
Can I please get a program of is empty like a complete program before 14
all of the code samples are on github -- github.com/anthonywritescode/explains
@@anthonywritescode thank you so much for these programs it means alot i was looking forward to it for my exams 💜💜
why is i better to use deque? And when should I use it in real projects?
as covered in the video -- it has different performance characteristics than a standard list and is useful for implementing things where random access is unimportant but access at ends is (queues are a big example, lru another)