What is the main advantage of using a doubly linked list over a singly linked list?
a) Each node points to both the previous and the next node, allowing for bidirectional traversal
b) It uses less memory than a singly linked list
c) It allows direct access to the middle of the list
d) It has a faster search time
Answer:
a) Each node points to both the previous and the next node, allowing for bidirectional traversal
Explanation:
The main advantage of a doubly linked list over a singly linked list is that each node contains two pointers: one to the next node and one to the previous node. This allows traversal in both directions, making it more flexible for operations like deletion and insertion at both ends.
However, a doubly linked list uses more memory than a singly linked list due to the additional pointer. Despite this, it is preferred in scenarios where bidirectional traversal is important, such as in certain sorting algorithms.
Searching in a linked list still takes linear time O(n), regardless of whether it is singly or doubly linked.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers