Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the front pointer of the circular queue.
DSA Python
class CircularQueue: def __init__(self, size): self.size = size self.queue = [None] * size self.front = [1] self.rear = -1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front to 0 initially causes confusion between empty and full states.
✗ Incorrect
The front pointer is initialized to -1 to indicate the queue is empty initially.
2fill in blank
mediumComplete the code to check if the circular queue is full.
DSA Python
def is_full(self): return (self.rear + 1) % self.size == [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with rear or 0 instead of front causes wrong full condition.
✗ Incorrect
The queue is full when the next position of rear is front.
3fill in blank
hardFix the error in the enqueue method to update the rear pointer correctly.
DSA Python
def enqueue(self, data): if self.is_full(): print("Queue is full") return if self.front == -1: self.front = 0 self.rear = [1] self.queue[self.rear] = data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing rear without modulo causes index out of range errors.
✗ Incorrect
The rear pointer must move forward circularly using modulo to wrap around.
4fill in blank
hardFill both blanks to correctly update the front pointer in the dequeue method.
DSA Python
def dequeue(self): if self.front == -1: print("Queue is empty") return None data = self.queue[self.front] if self.front == self.rear: self.front = [1] self.rear = [2] else: self.front = (self.front + 1) % self.size return data
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front or rear to 0 instead of -1 causes incorrect empty state.
✗ Incorrect
When the last element is dequeued, both front and rear reset to -1 to indicate empty queue.
5fill in blank
hardFill in the blanks to complete the display method that prints the queue elements in order.
DSA Python
def display(self): if self.front == -1: print("Queue is empty") return i = self.front while True: print(self.queue[i], end=" ") if i == self.rear: break i = (i [1] 1) [2] self.size print() # Example usage: cq = CircularQueue(5) cq.enqueue(10) cq.enqueue(20) cq.enqueue(30) cq.display() # Output: 10 20 30
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or floor division causes wrong index updates.
✗ Incorrect
To move forward circularly, add 1 and take modulo with size.