Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Python
new_node = Node([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' or 'tail' instead of the actual value.
Passing None instead of the value.
✗ Incorrect
We create a new node by passing the value to the Node constructor.
2fill in blank
mediumComplete the code to check if the queue is empty before enqueue.
DSA Python
if self.tail is [1]:
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing tail to head instead of None.
Using 'new_node' in the condition.
✗ Incorrect
If tail is None, the queue is empty and we need to set head and tail to the new node.
3fill in blank
hardFix the error in linking the new node at the end of the queue.
DSA Python
self.tail.[1] = new_node Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Trying to assign to 'head' or 'value' instead.
✗ Incorrect
The 'next' pointer of the current tail should point to the new node.
4fill in blank
hardFill both blanks to update the tail pointer after enqueue.
DSA Python
self.tail = [1] self.tail.[2] = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting tail to head instead of new_node.
Using 'prev' instead of 'next' for the pointer.
✗ Incorrect
After adding the new node, tail should point to it, and its next should be None.
5fill in blank
hardFill all three blanks to complete the enqueue method using linked list.
DSA Python
def enqueue(self, value): new_node = Node([1]) if self.tail is [2]: self.head = new_node self.tail = new_node else: self.tail.[3] = new_node self.tail = new_node
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to link nodes.
Not updating tail after adding new node.
Checking tail against head instead of None.
✗ Incorrect
We create a new node with the value, check if tail is None (empty queue), set head and tail to new node if empty, else link new node at tail.next and update tail.