What is the advantage of a bi-directional linked list over a unidirectional linked list?


#1

Question

Why would you choose to implement a bi-directional linked list versus a unidirectional linked list?

Answer

A bi-directional linked list (also known as a doubly linked list) allows the list to easily be traversed in the forward or reverse direction. A unidirectional linked list (also known as singly linked) allows for easy traversal in one direction but attempting to traverse the list in the opposite direction requires additional logic and the storing of links to prior elements. Although the bi-directional linked list requires an additional pointer to the prior element and some additional logic to update both links when an element is added or removed, having links to the prior and next element allows for easy traversal in either direction. If traversing the list in forward and reverse directions is a requirement, then the bi-directional linked list should be the preferred implementation.