Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the queue size.
DSA Python
queue = [None] * [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or None will not create a usable queue array.
✗ Incorrect
The queue is initialized with a fixed size of 10 to hold elements.
2fill in blank
mediumComplete the code to check if the queue is empty.
DSA Python
def is_empty(front): return front == [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 0 or None will not correctly detect empty queue.
✗ Incorrect
The queue is empty when the front index is -1.
3fill in blank
hardFix the error in the enqueue function to update rear correctly.
DSA Python
def enqueue(queue, rear, item, max_size): if rear == max_size - 1: print('Queue is full') return rear rear = rear [1] 1 queue[rear] = item return rear
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - will move rear backward causing errors.
✗ Incorrect
To add an item, rear index must increase by 1 using + operator.
4fill in blank
hardFill both blanks to correctly dequeue an item and update front.
DSA Python
def dequeue(queue, front, rear): if front == [1]: print('Queue is empty') return front, None item = queue[front] if front == rear: front = [2] rear = -1 else: front += 1 return front, item
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong values for empty queue check or reset.
✗ Incorrect
If front is -1, queue is empty. When last item is dequeued, front resets to 0 and rear to -1.
5fill in blank
hardFill all three blanks to implement a function that prints the queue elements.
DSA Python
def print_queue(queue, front, rear): if front == [1]: print('Queue is empty') return i = front while i != rear: print(queue[i], end=' -> ') i = i [2] 1 print(queue[[3]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong empty check or wrong index for last element.
✗ Incorrect
Check if front is -1 for empty. Increment i by 1 to traverse. Print last element at rear index.