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 moving forward and backward through the list.
Click to reveal answer
beginner
What are the three parts of a node in a doubly linked list?
1. Data: stores the value. 2. Next pointer: points to the next node. 3. Previous pointer: points to the previous node.
Click to reveal answer
intermediate
Why does a doubly linked list have a previous pointer?
The previous pointer allows moving backward in the list, making it easier to traverse in both directions and to delete or insert nodes efficiently.
Click to reveal answer
beginner
Show a simple TypeScript class for a doubly linked list node.
What is the difference between singly and doubly linked lists?
Singly linked lists have nodes with only a next pointer, so you can only move forward. Doubly linked lists have both next and previous pointers, allowing movement forward and backward.
Click to reveal answer
What does the 'prev' pointer in a doubly linked list node point to?
AThe previous node
BThe next node
CThe head of the list
DThe tail of the list
✗ Incorrect
The 'prev' pointer always points to the previous node in the list, enabling backward traversal.
Which of these is NOT a part of a doubly linked list node?
AData
BNext pointer
CPrevious pointer
DRandom pointer
✗ Incorrect
A standard doubly linked list node has data, next, and previous pointers. A random pointer is not part of the basic design.
Why might you choose a doubly linked list over a singly linked list?
ATo save memory
BTo allow backward traversal
CTo simplify node structure
DTo avoid using pointers
✗ Incorrect
Doubly linked lists allow moving backward through the list, which singly linked lists cannot do.
In TypeScript, how do you declare a node's next pointer that can be null?
Anext: Node<T>;
Bnext: null;
Cnext: Node<T> | null;
Dnext: undefined;
✗ Incorrect
The next pointer can point to another node or be null if it is the last node.
What happens to the 'prev' pointer of the node after the one you delete in a doubly linked list?
AIt points to the node before the deleted node
BIt points to the deleted node
CIt points to the node after the deleted node
DIt points to null
✗ Incorrect
After deletion, the 'prev' pointer of the node after the deleted node is updated to point to the node before the deleted node.
Explain the structure of a doubly linked list node and why each part is important.
Think about how you can move through the list in both directions.
You got /4 concepts.
Describe how a doubly linked list differs from a singly linked list and one advantage of using it.
Focus on the pointers and traversal directions.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between a doubly linked list node and a singly linked list node?
easy
A. A doubly linked list node has pointers to both the previous and next nodes.
B. A doubly linked list node stores data in a different format.
C. A doubly linked list node can only point to the next node.
D. A doubly linked list node does not store any data.
Solution
Step 1: Understand node pointers in singly linked list
A singly linked list node has only one pointer to the next node.
Step 2: Understand node pointers in doubly linked list
A doubly linked list node has two pointers: one to the previous node and one to the next node.
Final Answer:
A doubly linked list node has pointers to both the previous and next nodes. -> Option A
Quick Check:
Doubly linked list nodes have two pointers [OK]
Hint: Remember: doubly linked means two directions [OK]
Common Mistakes:
Thinking doubly linked nodes only point forward
Confusing data storage with pointer structure
Assuming doubly linked nodes do not store data
2. Which of the following is the correct TypeScript syntax to define a doubly linked list node class with data of type number?
C. Change next and prev types to 'Node | null' to allow null assignment.
D. Initialize next and prev with new Node() instead of null.
Solution
Step 1: Analyze type declarations and assignments
next and prev are typed as Node but assigned null, which is invalid in TypeScript.
Step 2: Fix type to allow null
Changing next and prev types to 'Node | null' allows null assignment and fixes the error.
Final Answer:
Change next and prev types to 'Node | null' to allow null assignment. -> Option C
Quick Check:
Nullable pointers need 'Node | null' type [OK]
Hint: Allow null in pointer types to avoid errors [OK]
Common Mistakes:
Leaving next and prev as non-nullable types
Trying to assign new Node() without data
Removing constructor unnecessarily
5. You want to insert a new node with data 30 between two existing nodes in a doubly linked list: nodeA and nodeB, where nodeA.next = nodeB and nodeB.prev = nodeA. Which sequence of pointer updates correctly inserts the new node?