0
0
DSA Pythonprogramming~10 mins

Circular Queue Implementation Using Array in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A-1
B0
CNone
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front to 0 initially causes confusion between empty and full states.
2fill in blank
medium

Complete 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'
A-1
Bself.rear
C0
Dself.front
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with rear or 0 instead of front causes wrong full condition.
3fill in blank
hard

Fix 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'
Aself.rear + 1
B(self.rear + 1) % self.size
Cself.rear - 1
Dself.front + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing rear without modulo causes index out of range errors.
4fill in blank
hard

Fill 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'
A-1
B0
Cself.rear
Dself.front
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front or rear to 0 instead of -1 causes incorrect empty state.
5fill in blank
hard

Fill 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'
A+
B-
C%
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or floor division causes wrong index updates.