Recall & Review
beginner
What is the main goal when deleting a node at the end of a singly linked list?
To remove the last node and update the second last node's next pointer to NULL, effectively shortening the list by one node.
Click to reveal answer
beginner
In a singly linked list, why do we need to traverse the list to delete the last node?
Because singly linked lists do not have backward pointers, we must traverse from the head to find the second last node to update its next pointer.
Click to reveal answer
beginner
What happens if you try to delete the last node in a singly linked list that has only one node?
The head pointer becomes NULL, indicating the list is now empty after deleting the only node.
Click to reveal answer
intermediate
Show the key steps in C to delete the last node of a singly linked list.
1. Check if the list is empty (head == NULL). 2. If only one node, free it and set head to NULL. 3. Otherwise, traverse to second last node. 4. Free last node. 5. Set second last node's next to NULL.
Click to reveal answer
beginner
Why is it important to free the memory of the deleted node in C?
To avoid memory leaks by releasing the allocated memory back to the system after the node is no longer used.
Click to reveal answer
What pointer do you update when deleting the last node in a singly linked list?
✗ Incorrect
You update the next pointer of the second last node to NULL to remove the last node.
If a singly linked list has only one node, what should happen after deleting that node?
✗ Incorrect
After deleting the only node, the list becomes empty, so head should be NULL.
Why can't you directly access the second last node in a singly linked list?
✗ Incorrect
Singly linked lists only have next pointers, so you must traverse from head to find the second last node.
What is the time complexity of deleting the last node in a singly linked list?
✗ Incorrect
You must traverse the list to find the second last node, which takes O(n) time.
What happens if you forget to free the deleted node's memory in C?
✗ Incorrect
Not freeing memory causes memory leaks, wasting system resources.
Explain step-by-step how to delete the last node in a singly linked list in C.
Think about what pointers you need to update and when to free memory.
You got /5 concepts.
Describe why deleting the last node in a singly linked list takes O(n) time.
Consider how the list is connected and what information is missing.
You got /4 concepts.
