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 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's next pointer to the current head.
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 None instead of head.
Setting new_node.next to new_node itself.
✗ Incorrect
The new node's next pointer should point to the current head node.
3fill in blank
hardFix the error in updating the previous pointer of the old head node.
DSA Python
if head is not None: head.[1] = new_node
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating head.next instead of head.prev.
Assigning head.data instead of a pointer.
✗ Incorrect
The previous pointer of the old head should point back to the new node.
4fill in blank
hardFill both blanks to update the head pointer and set the new node's previous pointer.
DSA Python
head = [1] head.[2] = None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to old head instead of new node.
Setting head.next to None instead of head.prev.
✗ Incorrect
The head pointer is updated to the new node, and its previous pointer is set to None.
5fill in blank
hardFill all three blanks to complete the insert_at_beginning function for a doubly linked list.
DSA Python
def insert_at_beginning(head, data): new_node = Node([1]) new_node.next = [2] if head is not None: head.prev = new_node head = new_node head.prev = [3] return head
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating the old head's prev pointer.
Setting new_node.prev incorrectly.
Returning the old head instead of the new head.
✗ Incorrect
We create a new node with data, link its next to the old head, update old head's prev, set head to new node, and set new head's prev to None.