Javatpoint Logo
Javatpoint Logo

Unrolled Linked List

A linear data structure called an unrolled linked list is a variant on the linked list. Unrolled linked lists store a full array at each node instead of simply one element at each node. Unrolled linked lists combine the advantages of an array (low memory overhead) with the advantages of linked lists (rapid insertion and deletion) to achieve dramatically improved performance. Unrolled linked lists effectively spread out the overhead of linked lists across several items by storing numerous elements at each node.

So, if each node of an unrolled linked list holds an array of four elements, the linked list overhead (pointers) is distributed across those four elements. When you examine the cache management of contemporary CPUs, Unrolled Linked List performs better. When compared to a standard, singly linked list, unrolled linked lists have a somewhat significant overhead per node. However, in most cases, this disadvantage is minor in comparison to the benefits of modern computers.

The unrolled linked list is a linked list in which each node carries an array of values rather than just one. Each node's array can contain anything that a conventional array can, including primitive kinds and other abstract data types. Each node can carry a maximum amount of values, and most implementations keep each node at about 3/4 capacity. When specific arrays become overflowing, it does so by transferring values between them.

The unrolled linked list has a somewhat higher per-node overhead since each node has to store the maximum number of values its array can carry. However, as compared to a standard linked list, it has a far cheaper per-value cost. The average storage space required per value decreases as the maximum size of the array in each node grows, and the space advantages are considerably bigger when the kind of value is very small. The unrolled linked list is a hybrid of an array and a linked list. It takes advantage of the array's ultra-fast indexing and storage locality. The underlying features of static arrays provide both of these advantages. Furthermore, it retains the linked list's advantage of node insertion and deletion.

The algorithm for inserting and deleting elements in an unrolled linked list varies depending on the implementation. The low-water mark is usually set at 50%, which means that if an element cannot be inserted into a node, a new node is constructed, and half of the current node's elements are entered into it. If we delete an element and the number of values in that node falls below 50%, we insert items from an adjacent array into that node to bring it back up to 50%. If that array also falls below 50%, the two nodes are merged.

This puts the average node's utilization at roughly 70-75 percent. With a decent node size, the overhead is quite low when compared to the linked list. Each node in a linked list requires about two or three pieces of overhead. The overhead of the unrolled linked list is amortized across its elements, giving it 1/size, which is similar to the overhead of an array. To adjust the performance of your unrolled linked list, change the low-water mark. You can raise the average utilization of each node by increasing it. This, however, will necessitate more frequent splitting and merging.

Java Code

Now let's write a Java code to implement an Unrolled Linked List which will perform all the basic functions like add, delete and display the node on the Unrolled Linked List.

Output:

The above code gives the following output.

Enter array size of each node
8
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
1
Enter integer element to insert
12

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
1
Enter integer element to insert
2

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
1
Enter integer element to insert
3

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
1
Enter integer element to insert
4

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
5
Contents of Unrolled Linked List are::

Unrolled Linked List = 
1 2 3 4 
Wrong Entry
 

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
2
Empty status = false

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
3
Size = 4


Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
5
Contents of Unrolled Linked List are::

Unrolled Linked List = 
1 2 3 4 

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
5
Contents of Unrolled Linked List are::

Unrolled Linked List = 
1 2 3 4 
Wrong Entry
 

Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
4
List Cleared


Do you want to continue (Type y or n)

y
Please Choose one of the Operations::
1. To insert Data in the Unrolled Linked List.
2. To Check List is empty or not.
3. To get the size of the Unrolled Linked List.
4. To clear the Unrolled Linked List.
5. To print/display the Data in the Unrolled Linked List.
5
Contents of Unrolled Linked List are::

Unrolled Linked List = empty
Wrong Entry
 

Do you want to continue (Type y or n)

n

Advantages

Here are the following advantages of unrolled linked list, such as:

  • In unrolled linked lists, linear search is substantially faster due to the Cache behavior.
  • It takes up less storage space for pointers/references than a traditional linked list.
  • It is faster than typically linked lists at operations like insertion, deletion, and traversal (because search is faster).






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA