Queue Data Structure
Aya Bouchiha
Posted on June 15, 2021
Hi, today, we're going to discuss queue :)
Definition Of Queue
A Queue is a linear data structure that stores items in a First-In/First-Out (FIFO) manner. In Queue, the element that goes in first is the element that comes out first.
Space and Time complexity
the space complexity of a queue is O(n)
add ( enqueue ) | remove (dequeue) | search | access |
---|---|---|---|
O(1) | O(1) | O(n) | O(n) |
Implementation of queue using python
class Queue:
def __init__(self,size):
self.items = []
self.front = self.rear = 0
self.size = size
Enqueue
def enqueue(self,data):
if not self.isFull() :
self.items.append(data)
self.rear += 1
return f'{self.items[-1]} added'
else:
return 'full'
Dequeue
def dequeue(self):
if not self.isEmpty() :
self.items.pop(0)
self.rear -= 1
return 'deleted successfuly'
return 'empty'
isEmpty
def isEmpty(self) -> bool:
return self.rear == self.front
isFull
def isFull(self) -> bool :
return self.size == self.rear
References and useful ressources
- https://www.geeksforgeeks.org/queue-in-python/
- https://www.geeksforgeeks.org/queue-data-structure/
- https://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm
- https://www.youtube.com/watch?v=A3ZUpyrnCbM
- https://www.youtube.com/watch?v=wjI1WNcIntg
#day_3
Have a good day!
💖 💪 🙅 🚩
Aya Bouchiha
Posted on June 15, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.