Linked data structure
In computer science, a linked data structure is a data structure which consists of a set of data records (nodes) linked together and organized by references (links or pointers).
In linked data strcutures, the links are usually treated as special data types that can only be derefrenced or compared for equality. Linked data strcutures are thus contrasted with arrays and other data strcutures that are perform arithmetic operations on pointers. This distinction holds even when the nodes are actually implemented as elements of a single array, and the references are actually array indices: as long as no arithmetic is done on those indices, the data strcuture is essentially a linked one.
Linked data strcutures include linked lists, search trees, expression trees, and many other widely used data strcutures. They are also key building blocks for many efficient algorithms, such as topological sort[1] and set union-find[2].
Advantages and disadvantages
Compared to arrays, linked data structures allow more flexibility in organizing the data and in allocating space for it. The nodes of a linked data strcuture can be moved individually to different locations without affecting the logical connections between them. With due care, a process can add or delete nodes to one part of a data structure even while other processes are working on other parts.
On the other hand, access to any particular node in a linked data structure requires following a chain of references that stored in it. If the strcuture has n nodes, and each node contains at most b links, there will be some nodes that cannot be reached in less than logb n steps. For many strcutures, some nodes may require worst case up to n−1 steps. In contrast, many array data strcutures allow access to any element with a constant number of operations, independent of the number of entries.
Linked data strcutures also may also incur in substantial memory allocation overehad (if nodes are allocated individually) and frustrate memory paging and processor caching algorithms (since they generally have poor locality of reference).In some cases, linked data strcutures may also use more memory (for the link fields) than competing array strctures.
In some theoretical models of computation that enforce the constraints of linked structures, such as the pointer machine, many problems require more steps than in the unconstrained random access machine model.
References
- ^ Donald Knuth, The Art of Computer Programming
- ^ Bernard A. Galler and Michael J. Fischer. An improved equivalence algorithm. Communications of the ACM, Volume 7, Issue 5 (May 1964), pages 301-303. The paper originating disjoint-set forests. ACM Digital Library