One Pager Cheat Sheet
- A queue is a collection of items whereby its operations are arranged in a
FIFO(First In First Out) format and involve two main operations:enqueueanddequeue. - The queue is a data structure with two open ends, the rear for adding elements and the front for removing them, which follows the
First In First Out (FIFO)principle. - Queues work on the First In First Out (FIFO) principle of
enqueuinganddequeuingelements. - A Queue has two main operations - Enqueue to add elements and Dequeue to remove elements.
- The
enqueueoperation adds elements to the rear end of thequeue, and updates thefrontandrearpointer accordingly. - To
dequeuean element from a queue, it is removed from the front end, if it is present, and at least one element must be in the queue for it to be possible. - Dequeuing an element from the queue does not affect the
frontpointer, which remains the same, pointing at the first element added, while therearpointer increases with new elements. - We can implement queues using a
list,collections.deque, orqueue.Queueinpython, with thelistinvolving costlyO(n)time complexity but with the use of the round-robin technique also requiringO(1)time, or usingcollections.dequeorqueue.QueuerequiringO(1)time complexity. - The complexity of implementing a queue with a
listclass in any programming language is O(n) due to the time needed to shift all items on each addition or deletion. - We can quickly
enqueueanddequeueitems in a queue using most languages by either using alistorarray, or with more efficient time complexity by implementing a fixed-sized list with two pointers. - The
Linked Listimplementation ofQueuesis similar to the Linked List implementation ofStackswe used previously. - The python library provides the
queueclass from theQueuemodule to enable users to implement simple queues and check for the empty and full conditions using theempty()andfull()functions respectively. - We can implement a
queueusing thedequeclass from the collections module toappend()andpopleft()elements from the queue. - The
dequeclass from thecollectionsmodule can be used topopleft()the first element and reduce the size of the queue in Python. - The FIFO approach and using
collectionsare effective approaches forimplementing queuesin python.

