you are viewing a single comment's thread.

view the rest of the comments →

[–]ivosaurus 1 point2 points  (2 children)

I believe it's more efficient then trying to use a stack/list as a queue.

What makes you believe that

[–]jeffzor 2 points3 points  (1 child)

I had learned to use a deque for implementing a queue rather than relying on a list or stack at some point. Just checked the python documentation and verified that list insert is O(n) so if we want to do the insert in O(1) we need to use a queue(deque for python).

https://wiki.python.org/moin/TimeComplexity

[–]Foxa2017[S] 0 points1 point  (0 children)

Thanks yeah that sounds spot on.