Recall & Review
beginner
What is a doubly linked list?
A doubly linked list is a chain of nodes where each node has two links: one to the next node and one to the previous node. This allows moving forward and backward through the list.
Click to reveal answer
beginner
What happens when you delete the first node in a doubly linked list?
The first node is removed, the head pointer moves to the second node, and the new first node's previous link is set to NULL.
Click to reveal answer
beginner
Why do we set 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 before it, so its previous pointer must be NULL.
Click to reveal answer
beginner
What should you check before deleting the first node in a doubly linked list?
Check if the list is empty (head is NULL). If empty, no deletion is possible.
Click to reveal answer
intermediate
Show the C code snippet to delete the first node of a doubly linked list.
if (head == NULL) return;
Node* temp = head;
head = head->next;
if (head != NULL) head->prev = NULL;
free(temp);
Click to reveal answer
What pointer must be updated after deleting the first node in a doubly linked list?
✗ Incorrect
After deleting the first node, the head pointer moves to the next node, and the new head's previous pointer must be set to NULL.
What should you do if the doubly linked list is empty when trying to delete the first node?
✗ Incorrect
If the list is empty (head is NULL), there is no node to delete, so the function should simply return.
After deleting the first node, what happens if the list had only one node?
✗ Incorrect
If the list had only one node, deleting it makes the list empty, so head becomes NULL.
Which function is used to free the memory of the deleted node in C?
✗ Incorrect
In C, free() is used to release the memory allocated to a node.
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 a few pointers only.
Explain step-by-step how to delete the first node from a doubly linked list.
Think about what pointers need to change and how to avoid memory leaks.
You got /5 concepts.
Describe what happens to the doubly linked list structure after deleting the first node.
Visualize the list before and after deletion.
You got /4 concepts.
