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' instead of 'data' when creating the new node.
Passing 'None' or 'next' instead of the data value.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA Python
new_node.next = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node.next to itself.
Setting new_node.next to None or data.
✗ Incorrect
The new node's next pointer should point to the current head node.
3fill in blank
hardFix the error in updating the head pointer 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 data or None instead of new_node.
Assigning head to head.next which skips the new node.
✗ Incorrect
After insertion, the head should point to the new node.
4fill in blank
hardFill both blanks to complete the function that inserts a new node at the beginning.
DSA Python
def insert_at_beginning(head, [1]): new_node = Node(data) new_node.next = [2] head = new_node return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head.next' instead of 'head' for new_node.next.
Using 'new_node' as a parameter instead of 'data'.
✗ Incorrect
The function takes 'data' as input and links new_node.next to current head.
5fill in blank
hardFill all three blanks to complete the full insert at beginning function with Node class.
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None def insert_at_beginning([1], [2]): new_node = Node(data) new_node.next = [3] head = new_node return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping parameter order or names.
Setting new_node.next to new_node instead of head.
✗ Incorrect
The function takes head and data, links new_node.next to head, and returns new_node as new head.