A linked list is a linear data structure that stores a collection of data elements dynamically. It consists of a sequence of nodes, where each node contains a data field and a reference (link) to the next node in the list. Unlike arrays, linked lists do not store elements in contiguous memory locations. Instead, each element points to the next, and the order of the elements is not given by their physical placement in memory.
Linked lists are among the simplest and most common data structures, and they can be used to implement several other common abstract data types, including lists, stacks, queues, associative arrays, and S-expressions. Linked lists allow insertion and removal of nodes at any point in the list, and this can be done with a constant number of operations by keeping the link previous to the link being added or removed in memory during list traversal.
There are three types of linked lists: singly linked lists, doubly linked lists, and circular linked lists. Singly linked lists consist of nodes that only point to the address of the next node in the list, while doubly linked lists consist of nodes that point to both the previous and next nodes in the list. Circular linked lists are similar to singly or doubly linked lists, but the last node points back to the first node instead of null.
Linked lists can be implemented using references together with records in languages that do not support abstract data types or templates. In languages that support abstract data types or templates, linked list ADTs or templates are available for building linked lists.
Some of the applications of linked lists include implementing stacks and queues, implementing an adjacency matrix graph, dynamic memory location, addition and multiplication of polynomial operations, and implementing a hash table. Linked lists are also used in the functionality known as undo in Photoshop and Word.