Linked Lists

A linked list is a dynamically-resizable alternative to an array, made of nodes that contain pointers to other nodes. The main advantage of a linked list is its dynamism: that is to say it can be used to store data even if the programmer does not know how much data must be stored. This dynamism, however, comes at the cost of (a) memory, as extra space is required to store all the pointers, as well as (b) time, as binary search is no longer a possibility without random access. Linked lists are an alternative to arrays when implementing stacks and queues, earlier sections in this chapter. In this section, we will discuss singly linked lists in detail, as well as briefly touch on doubly linked lists, go over the trade-offs associated with using this data structure, as well as revisit stacks and queues to see how they can be implemented with a linked list.