GFG App
Open App
Browser
Continue

# Unrolled Linked List | Set 1 (Introduction)

Like array and linked list, the unrolled Linked List is also a linear data structure and is a variant of a linked list.

Why do we need unrolled linked list?

• Because of the Cache behavior, linear search is much faster in unrolled linked lists.
• In comparison to the ordinary linked list, it requires less storage space for pointers/references.
• It performs operations like insertion, deletion, and traversal more quickly than ordinary linked lists (because search is faster).

• The overhead per node is comparatively high than singly-linked lists. Refer to an example node in the below code

Example: Let say we are having 8 elements so sqrt(8)=2.82 which rounds off to 3. So each block will store 3 elements. Hence, to store 8 elements 3 blocks will be created out of which the first two blocks will store 3 elements and the last block would store 2 elements.

How searching becomes better in unrolled linked lists?

So taking the above example if we want to search for the 7th element in the list we traverse the list of blocks to the one that contains the 7th element. It takes only O(sqrt(n)) since we found it through not going more than sqrt(n) blocks.

Simple Implementation:

The below program creates a simple unrolled linked list with 3 nodes containing a variable number of elements in each. It also traverses the created list.

## Javascript



Output

1 2 3 4 5 6 7 8 9

Complexity Analysis:

• Time Complexity: O(n).
• Space Complexity: O(n).

In this article, we have introduced an unrolled list and advantages of it. We have also shown how to traverse the list. In the next article, we will be discussing the insertion, deletion, and values of maxElements/numElements in detail.