What is a Queue and Implementing a Queue class in Python

Опубликовано: 23 Февраль 2026
на канале: Nathan Patnam
4,044
37

One portion of the video that I didn't spend as much time as I would have liked on was why I chose to use Nodes as opposed to a List to implement the Queue class. The reason for this is that by using Nodes the time complexity of enqueue and dequeue would be O(1). With a list the time complexity of enqueue and dequeue would be O(1) and O(n) respectively and here is why. To append to a list which is what enqueue is (when implementing a queue with a list) is O(1). However, to remove the first item, which is what dequeue basically is, in a list with the pop method i.e my_list.pop(0) takes O(n) time since you have to move every item to the right of the item being removed one place over to the left.

Code at : https://github.com/Nathan-Patnam/Data...

Follow/Connect with me on:
  / nathan-patnam  
https://github.com/Nathan-Patnam
https://www.upwork.com/fl/nathanpatnam