0
0
DSA Pythonprogramming~10 mins

Dequeue Using Linked List 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 add a new node at the front of the dequeue.

DSA Python
def add_front(self, data):
    new_node = Node(data)
    if self.front is None:
        self.front = self.rear = new_node
    else:
        new_node.next = [1]
        self.front.prev = new_node
        self.front = new_node
Drag options to blanks, or click blank then click option'
Aself.front
Bself.rear
Cnew_node
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node.next to None instead of the current front.
Confusing front and rear pointers.
2fill in blank
medium

Complete the code to remove a node from the rear of the dequeue.

DSA Python
def remove_rear(self):
    if self.rear is None:
        return None
    data = self.rear.data
    self.rear = self.rear.prev
    if self.rear is not None:
        self.rear.next = [1]
    else:
        self.front = None
    return data
Drag options to blanks, or click blank then click option'
ANone
Bself.front
Cself.rear
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Setting rear.next to rear itself causing a cycle.
Not updating front when list becomes empty.
3fill in blank
hard

Fix the error in the code to add a node at the rear of the dequeue.

DSA Python
def add_rear(self, data):
    new_node = Node(data)
    if self.rear is None:
        self.front = self.rear = new_node
    else:
        self.rear.next = new_node
        new_node.prev = [1]
        self.rear = new_node
Drag options to blanks, or click blank then click option'
Aself.front
Bself.rear
Cnew_node
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node.prev to new_node causing self-reference.
Setting new_node.prev to front instead of rear.
4fill in blank
hard

Fill both blanks to correctly remove a node from the front of the dequeue.

DSA Python
def remove_front(self):
    if self.front is None:
        return None
    data = self.front.data
    self.front = self.front.[1]
    if self.front is not None:
        self.front.[2] = None
    else:
        self.rear = None
    return data
Drag options to blanks, or click blank then click option'
Anext
Bprev
Cfront
Drear
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front to front.prev which moves backward incorrectly.
Not clearing the prev pointer of the new front node.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each node's data to its position if data is positive.

DSA Python
def map_positive_nodes(self):
    result = {node.data[1]: idx for idx, node in enumerate(self.iterate()) if node.data [2] 0 and node.data is not [3] None}
    return result
Drag options to blanks, or click blank then click option'
A * 2
B>
C==
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '+' for key expression.
Using '==' instead of '>' for filtering positive data.
Checking data is None with '==' instead of 'is not'.