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 'next' instead of the data value.
Passing 'head' which is the start of the list, not the new data.
✗ Incorrect
We pass the data value to the Node constructor to create a new node with that data.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA Python
new_node.[1] = head Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' or 'value' instead of 'next'.
Trying to assign to 'prev' which is not used in singly linked list.
✗ Incorrect
The 'next' pointer of the new node should point to the current head to insert it at the front.
3fill in blank
hardFix the error in updating the head to point to the new node.
DSA Python
head = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to new_node.next which skips the new node.
Assigning head to None which empties the list.
✗ Incorrect
After linking, the head must be updated to the new node to reflect the new start of the list.
4fill in blank
hardFill both blanks to complete the push function that adds a new node at the front.
DSA Python
def push(head, data): new_node = Node([1]) new_node.[2] = head head = new_node return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for linking.
Passing wrong variable to Node constructor.
✗ Incorrect
We create a new node with the data, link its next to head, then update head to new_node.
5fill in blank
hardFill all three blanks to complete the push function with variable names and pointer updates.
DSA Python
def push([1], [2]): new_node = Node([2]) new_node.[3] = [1] [1] = new_node return [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names in parameters and inside function.
Using wrong pointer name instead of 'next'.
✗ Incorrect
The function takes head and data, creates new_node with data, links new_node.next to head, updates head to new_node, and returns head.