Lably
Skip to content

Linked data structure

Way of storing data in a computer

  • 4 min read
  • 2 chapters

Related on Lably

Through Computer science, Data structure and Record (computer science)

In linked data structures, the links are usually treated as special data types that can only be dereferenced or compared for equality. Linked data structures are thus contrasted with arrays and other data structures that require performing 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 structure is essentially a linked one.

Linking can be done in two ways – using dynamic allocation and using array index linking.

Linked data structures include linked lists, search trees, expression trees, and many other widely used data structures. They are also key building blocks for many efficient algorithms, such as topological sort and set union-find.

Common types of linked data structures

Linked lists

A linked list is a collection of structures ordered not by their physical placement in memory but by logical links that are stored as part of the data in the structure itself. It is not necessary that it should be stored in the adjacent memory locations. Every structure has a data field and an address field. The Address field contains the address of its successor.

Linked list can be singly, doubly or multiply linked and can either be linear or circular.

Basic properties
  • Objects, called nodes, are linked in a linear sequence.
  • A reference to the first node of the list is always kept. This is called the 'head' or 'front'.


A linked list with three nodes contain two fields each: an integer value and a link to the next node

Pseudocode

The layout of a linked list storing elements of type T can appear like so:

<span id="mwRw"></span><span class="k" id="mwSA">struct</span><span class="w" id="mwSQ"> </span><span class="nc" id="mwSg">LinkedList</span><span class="w" id="mwSw"> </span><span class="p" id="mwTA">{</span> <span class="w" id="mwTQ"> </span><span class="n" id="mwTg">T</span><span class="w" id="mwTw"> </span><span class="n" id="mwUA">value</span><span class="p" id="mwUQ">;</span><span class="w" id="mwUg"> </span><span class="c1" id="mwUw">// stored value</span> <span class="w" id="mwVA"> </span><span class="n" id="mwVQ">LinkedList</span><span class="w" id="mwVg"> </span><span class="n" id="mwVw">next</span><span class="p" id="mwWA">;</span><span class="w" id="mwWQ"> </span><span class="c1" id="mwWg">// reference to the next node (or null if last node)</span> <span class="p" id="mwWw">}</span>

Search trees

A search tree is a tree data structure in whose nodes data values can be stored from some ordered set, which is such that in an in-order traversal of the tree the nodes are visited in ascending order of the stored values.

Basic properties
  • Objects, called nodes, are stored in an ordered set.
  • In-order traversal provides an ascending readout of the data in the tree.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication