00:00

Types of Linked List in Data Structures

Last updated:

Every linked list is a chain of nodes, where each node stores a value and one or more references to other nodes. The kinds of linked list differ in two choices: how many links each node carries, and whether the last node leads back to the first.

Singly linked list: head points to the first node, each node points to the next, and the last node points to null

Types of Linked Lists in Data Structures

There are three basic types:

  1. Singly Linked List: one link per node, pointing forward.

  2. Doubly Linked List: two links per node, pointing forward and backward.

  3. Circular Linked List: the last node links back to the first.

A circular list can itself be singly or doubly linked, which is why some books count four types (circular singly and circular doubly listed separately).

1. Singly Linked List

In a singly linked list, each node has a data field and a single next reference to the node after it. The list is reached through the head reference; an empty list has a null head, and the last node's next is null.

Singly linked list with nodes linked in one direction and the last node pointing to null

Because a node knows only its successor, a singly linked list can be walked in the forward direction only. It uses the least memory of the three types.

2. Doubly Linked List

A doubly linked list is a linked list in which every node also remembers the node before it. Each node therefore has three fields: a prev reference, the data, and a next reference.

With links in both directions, the list can be traversed forward and backward, and a node can be removed in O(1) when you already hold a reference to it, because its predecessor is directly available. The cost is one extra reference per node.

Doubly linked list with prev and next links between neighbouring nodes

A doubly linked list node has three parts:

Doubly linked list node: prev reference, data, next reference
  1. First Part: the reference to the previous node (null in the first node).
  2. Second Part: the value stored in the node.
  3. Third Part: the reference to the next node (null in the last node).

Circular Linked List

In a circular linked list, the last node links back to the first node instead of holding null. There is no natural end, so a traversal stops when it returns to the node where it started.

Circular linked list where the last node points back to the first node

Circular lists suit jobs that cycle through items repeatedly, such as round-robin scheduling. Like the other types, they grow and shrink one node at a time.