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
Why do we need to update both next and prev pointers when inserting in a doubly linked list?
Because each node points to both its next and previous nodes, when inserting a new node, we must update the next pointer of the previous node and the prev pointer of the next node to keep the list connected correctly.
Click to reveal answer
intermediate
What happens if you try to insert a node at a position greater than the list length?
The insertion should fail or be handled gracefully because the position is invalid. The list does not have that many nodes, so you cannot insert there.
Click to reveal answer
beginner
In C, what is the typical structure of a node in a doubly linked list?
A typical node has a data field (e.g., int data), a pointer to the next node (struct Node* next), and a pointer to the previous node (struct Node* prev).
Click to reveal answer
intermediate
What is the time complexity of inserting a node at a specific position in a doubly linked list?
The time complexity is O(n) because you may need to traverse up to n nodes to reach the desired position before inserting.
Click to reveal answer
Which pointer(s) must be updated when inserting a new node between two nodes in a doubly linked list?
✗ Incorrect
Both the next pointer of the previous node and the prev pointer of the next node must be updated to link the new node correctly.
What is the first step when inserting at position 1 in a doubly linked list?
✗ Incorrect
Inserting at position 1 means inserting at the head, so you create a new node and update the head pointer.
If the list is empty, what happens when you insert at position 1?
✗ Incorrect
When the list is empty, inserting at position 1 creates the first node, which is both head and tail.
Which of these is NOT a valid position to insert in a list of length 3?
✗ Incorrect
For a list of length 3, valid positions are 1, 2, 3, and 4 (insertion at the end). Position 4 is valid for insertion at the end, so the invalid position is 5 or greater.
What does the prev pointer of the head node point to?
✗ Incorrect
The prev pointer of the head node points to NULL because there is no node before the head.
Explain step-by-step how to insert a new node at a specific position in a doubly linked list.
Think about how nodes link forward and backward.
You got /5 concepts.
Describe how the pointers change when inserting a node in the middle of a doubly linked list.
Focus on the four pointer updates needed.
You got /4 concepts.
