What is a Queue and Implementing a Queue class in Python

Published: 12 February 2018
on channel: 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


On this page of the site you can watch the video online What is a Queue and Implementing a Queue class in Python with a duration of hours minute second in good quality, which was uploaded by the user Nathan Patnam 12 February 2018, share the link with friends and acquaintances, this video has already been watched 4,044 times on youtube and it was liked by 37 viewers. Enjoy your viewing!