0
0
DSA Pythonprogramming~10 mins

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 queue size.

DSA Python
queue = [None] * [1]
Drag options to blanks, or click blank then click option'
A10
B5
C0
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or None will not create a usable queue array.
2fill in blank
medium

Complete 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'
A0
Bfront
C-1
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 0 or None will not correctly detect empty queue.
3fill in blank
hard

Fix 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'
A-
B*
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using - will move rear backward causing errors.
4fill in blank
hard

Fill 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'
A-1
B0
Cfront
Drear
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong values for empty queue check or reset.
5fill in blank
hard

Fill 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'
A-1
B+
Crear
Dfront
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong empty check or wrong index for last element.