Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
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 data value.
Passing None instead of the data.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to check if the list is empty.
DSA Python
if head is [1]:
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head is tail instead of None.
Using assignment '=' instead of comparison 'is'.
✗ Incorrect
An empty list has head equal to None.
3fill in blank
hardFix the error in linking the new node to the list when the list is not empty.
DSA Python
new_node.next = [1].next [1].next = new_node head = new_node.next
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of tail to link the new node.
Setting new_node.next to None.
✗ Incorrect
We link the new node after the tail, so we use tail.next and update tail.next to new_node.
4fill in blank
hardFill both blanks to update the tail pointer and maintain circularity.
DSA Python
tail = [1] tail.next = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating tail to new_node.
Setting tail.next to None breaking circularity.
✗ Incorrect
After insertion, tail becomes the new node, and tail.next points to head to keep the list circular.
5fill in blank
hardFill all three blanks to complete the insert_at_end function for a circular linked list.
DSA Python
def insert_at_end(head, data): new_node = Node([1]) if head is None: new_node.next = new_node head = new_node else: tail = head while tail.next != [2]: tail = tail.next new_node.next = tail.next tail.next = new_node tail = [3] tail.next = head return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using tail instead of head in the while loop condition.
Not updating tail to new_node after insertion.
Passing wrong value to Node constructor.
✗ Incorrect
We create new_node with data, find tail by checking tail.next != head, then insert new_node after tail and update tail to new_node.