What is a key advantage of a doubly linked list compared to a singly linked list?
A doubly linked list allows traversal in both directions (forward and backward), while a singly linked list only allows forward traversal.
Click to reveal answer
intermediate
How does a doubly linked list improve deletion of a node compared to a singly linked list?
In a doubly linked list, deletion is easier because each node has a pointer to its previous node, so you don't need to traverse from the head to find the previous node.
Click to reveal answer
beginner
What extra memory cost does a doubly linked list have compared to a singly linked list?
Each node in a doubly linked list stores an extra pointer to the previous node, so it uses more memory than a singly linked list.
Click to reveal answer
beginner
Why might a doubly linked list be preferred for implementing a browser's back and forward navigation?
Because it allows moving both backward and forward easily, matching the back and forward buttons functionality.
Click to reveal answer
beginner
What is a disadvantage of using a doubly linked list over a singly linked list?
It requires more memory per node and slightly more complex code to maintain both next and previous pointers.
Click to reveal answer
Which linked list type allows traversal in both directions?
ASingly linked list
BCircular linked list
CDoubly linked list
DNone of the above
✗ Incorrect
Doubly linked lists have pointers to both next and previous nodes, enabling two-way traversal.
What extra pointer does a doubly linked list node have compared to a singly linked list node?
APointer to the head node
BPointer to the previous node
CPointer to the tail node
DPointer to the next node
✗ Incorrect
Doubly linked list nodes have a pointer to the previous node in addition to the next node.
Why is deletion easier in a doubly linked list?
ABecause it has only one pointer
BBecause nodes are stored in an array
CBecause it uses less memory
DBecause you can access the previous node directly
✗ Incorrect
Direct access to the previous node allows quick update of pointers during deletion.
What is a disadvantage of doubly linked lists?
AMore memory usage per node
BCannot traverse backwards
CSlower insertion at head
DNo pointers to next node
✗ Incorrect
Doubly linked lists use extra memory for the previous pointer.
Which scenario benefits most from a doubly linked list?
AImplementing undo and redo functionality
BSimple queue implementation
CStack implementation
DStatic array storage
✗ Incorrect
Undo and redo require moving backward and forward, which doubly linked lists support well.
Explain why a doubly linked list might be chosen over a singly linked list for certain applications.
Think about how moving backward and forward in a list helps in real life.
You got /4 concepts.
Describe the trade-offs between using a singly linked list and a doubly linked list.
Consider memory, speed, and complexity.
You got /4 concepts.
Practice
(1/5)
1. Why might you choose a doubly linked list over a singly linked list in a program?
easy
A. Because it uses less memory per node
B. Because it allows traversal in both directions easily
C. Because it is simpler to implement
D. Because it only stores one pointer per node
Solution
Step 1: Understand traversal capabilities
A singly linked list allows moving forward only, while a doubly linked list allows moving forward and backward.
Step 2: Compare memory and complexity
Doubly linked lists use more memory and are more complex but provide two-way traversal.
Final Answer:
Because it allows traversal in both directions easily -> Option B
Quick Check:
Two-way traversal = A [OK]
Hint: Doubly means two directions, singly means one [OK]
2. Which of the following is the correct way to declare a node in a doubly linked list in TypeScript?
easy
A. class Node { value: number; next: Node; }
B. class Node { value: number; prev: Node; }
C. class Node { value: number; next: Node | null; prev: Node | null; }
D. class Node { value: number; next: Node | null; }
Solution
Step 1: Identify required pointers for doubly linked list node
A doubly linked list node must have both next and prev pointers, which can be null if no neighbor exists.
Step 2: Check TypeScript syntax for nullable pointers
Using Node | null correctly allows for the end nodes to have null pointers.
Final Answer:
class Node { value: number; next: Node | null; prev: Node | null; } -> Option C
Quick Check:
Doubly linked node needs next and prev with nulls [OK]
Hint: Doubly linked nodes have next and prev pointers [OK]
Common Mistakes:
Omitting the prev pointer
Not allowing null for next or prev
Using only one pointer like singly linked list
3. Consider this TypeScript code snippet for a doubly linked list node insertion at the front:
class Node {
value: number;
next: Node | null = null;
prev: Node | null = null;
constructor(value: number) { this.value = value; }
}
class DoublyLinkedList {
head: Node | null = null;
insertFront(value: number) {
const newNode = new Node(value);
if (this.head) {
newNode.next = this.head;
this.head.prev = newNode;
}
this.head = newNode;
}
}
const list = new DoublyLinkedList();
list.insertFront(10);
list.insertFront(20);
list.insertFront(30);
let current = list.head;
const result = [];
while (current) {
result.push(current.value);
current = current.next;
}
console.log(result);
What will be printed?
medium
A. [10, 30, 20]
B. [10, 20, 30]
C. [20, 30, 10]
D. [30, 20, 10]
Solution
Step 1: Trace insertFront calls
First insert 10: list is 10. Then insert 20 at front: list is 20 -> 10. Then insert 30 at front: list is 30 -> 20 -> 10.
Step 2: Traverse from head to next
Starting at head (30), next is 20, then 10, then null. So collected values are [30, 20, 10].
Final Answer:
[30, 20, 10] -> Option D
Quick Check:
Insert front reverses order = [30, 20, 10] [OK]
Hint: Insert front adds new node before head [OK]
Common Mistakes:
Assuming insertion appends at end
Mixing order of traversal
Ignoring prev pointer effects
4. This TypeScript code tries to delete the last node from a doubly linked list but has a bug:
deleteLast() {
if (!this.head) return;
let current = this.head;
while (current.next) {
current = current.next;
}
current.prev.next = null;
}
What is the bug here?
medium
A. It does not handle the case when list has only one node
B. It incorrectly sets current.next to null instead of current.prev.next
C. It causes infinite loop in the while
D. It deletes the head node instead of the last node
Solution
Step 1: Analyze deletion logic
The code moves to the last node by following next pointers. Then it sets current.prev.next = null to remove last node.
Step 2: Check edge case for single node list
If list has only one node, current.prev is null, so current.prev.next causes error.
Final Answer:
It does not handle the case when list has only one node -> Option A
Quick Check:
Single node list needs special case [OK]
Hint: Check for single node before accessing prev [OK]
Common Mistakes:
Ignoring single node edge case
Assuming prev is always non-null
Confusing next and prev pointers
5. You want to implement a feature that requires frequent backward traversal from any node in a list. Which data structure is best and why?
Options:
A) Singly linked list because it uses less memory
B) Circular singly linked list because it loops infinitely
C) Array because it supports random access
D) Doubly linked list because it allows backward traversal efficiently
hard
A. Doubly linked list because it allows backward traversal efficiently
B. Circular singly linked list because it loops infinitely
C. Array because it supports random access
D. Singly linked list because it uses less memory
Solution
Step 1: Understand backward traversal need
Backward traversal means moving from a node to its previous nodes efficiently.
Step 2: Compare data structures for backward traversal
Singly linked lists do not have backward pointers. Arrays allow random access but not linked traversal. Circular singly linked lists loop but do not support backward traversal. Doubly linked lists have prev pointers for efficient backward moves.
Final Answer:
Doubly linked list because it allows backward traversal efficiently -> Option A
Quick Check:
Backward traversal needs prev pointers [OK]
Hint: Backward moves need prev pointers, only doubly linked lists have them [OK]
Common Mistakes:
Choosing singly linked list for backward traversal
Confusing arrays with linked lists
Thinking circular singly linked lists support backward moves
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.