Recall & Review
beginner
What is a doubly linked list?
A doubly linked list is a chain of nodes where each node has three parts: data, a pointer to the next node, and a pointer to the previous node. This allows traversal in both directions.
Click to reveal answer
beginner
What happens when you delete the first node in a doubly linked list?
The head pointer moves to the second node, and the new head's previous pointer is set to None. The old first node is removed from the list.
Click to reveal answer
intermediate
Why do we need to update the previous pointer of the new head to null after deletion?
Because the new head is now the first node, it should not point back to any node. Setting its previous pointer to None ensures the list starts correctly.
Click to reveal answer
beginner
What should you check before deleting the first node in a doubly linked list?
You should check if the list is empty (head is None). If it is empty, there is nothing to delete.
Click to reveal answer
intermediate
Show the Python code snippet to delete the first node from a doubly linked list.
def delete_from_beginning(head):
if head is None:
return None
new_head = head.next
if new_head is not None:
new_head.prev = None
return new_head
Click to reveal answer
What pointer must be updated when deleting the first node in a doubly linked list?
✗ Incorrect
After deletion, the new head's previous pointer must be set to None to mark it as the first node.
What should happen if the doubly linked list is empty and you try to delete from the beginning?
✗ Incorrect
If the list is empty (head is None), deletion does nothing and returns None.
After deleting the first node, what becomes the new head of the doubly linked list?
✗ Incorrect
The second node becomes the new head after the first node is deleted.
Which of these is NOT a part of a doubly linked list node?
✗ Incorrect
A standard doubly linked list node has data, next pointer, and previous pointer, but not a random pointer.
What is the time complexity of deleting the first node in a doubly linked list?
✗ Incorrect
Deleting the first node is a constant time operation because it involves updating only a few pointers.
Explain step-by-step how to delete the first node from a doubly linked list.
Think about what pointers need to change and what happens if the list is empty.
You got /4 concepts.
Write a simple Python function to delete the first node of a doubly linked list and return the new head.
Focus on pointer updates and edge cases.
You got /4 concepts.