An unrolled linked list is a linked list of small arrays, all of the same size where each is so small that the insertion or deletion is fast and quick, but large enough to fill the cache line. An iterator pointing into the list consists of both a pointer to a node and an index into that node containing an array. It is also a data structure and is another variant of Linked List. It is related to B-Tree. It can store an array of elements at a node unlike a normal linked list which stores single element at a node. It is combination of arrays and linked list fusion-ed into one. It increases cache performance and decreases the memory overhead associated with storing reference for metadata. Other major advantages and disadvantages are already mentioned in the previous article.
Prerequisite : Introduction to Unrolled Linked List
Below is the insertion and display operation of Unrolled Linked List.
Input : 72 76 80 94 90 70 capacity = 3 Output : Unrolled Linked List : 72 76 80 94 90 70 Explanation : The working is well shown in the algorithm below. The nodes get broken at the mentioned capacity i.e., 3 here, when 3rd element is entered, the flow moves to another newly created node. Every node contains an array of size (int)[(capacity / 2) + 1]. Here it is 2. Input : 49 47 62 51 77 17 71 71 35 76 36 54 capacity = 5 Output : Unrolled Linked List : 49 47 62 51 77 17 71 71 35 76 36 54 Explanation : The working is well shown in the algorithm below. The nodes get broken at the mentioned capacity i.e., 5 here, when 5th element is entered, the flow moves to another newly created node. Every node contains an array of size (int)[(capacity / 2) + 1]. Here it is 3.
Insert (ElementToBeInserted) if start_pos == NULL Insert the first element into the first node start_pos.numElement ++ end_pos = start_pos If end_pos.numElements + 1 < node_size end_pos.numElements.push(newElement) end_pos.numElements ++ else create a new Node new_node move final half of end_pos.data into new_node.data new_node.data.push(newElement) end_pos.numElements = end_pos.data.size / 2 + 1 end_pos.next = new_node end_pos = new_node
Following is the Java implementation of the insertion and display operation. In the below code, the capacity is 5 and random numbers are input.
Entered Element is 90 Unrolled Linked List = 90 Entered Element is 3 Unrolled Linked List = 90 3 Entered Element is 12 Unrolled Linked List = 90 3 12 Entered Element is 43 Unrolled Linked List = 90 3 12 43 Entered Element is 88 Unrolled Linked List = 90 3 12 43 88 Entered Element is 94 Unrolled Linked List = 90 3 12 43 88 94 Entered Element is 15 Unrolled Linked List = 90 3 12 43 88 94 15 Entered Element is 7 Unrolled Linked List = 90 3 12 43 88 94 15 7 Entered Element is 67 Unrolled Linked List = 90 3 12 43 88 94 15 7 67 Entered Element is 74 Unrolled Linked List = 90 3 12 43 88 94 15 7 67 74 Entered Element is 85 Unrolled Linked List = 90 3 12 43 88 94 15 7 67 74 85 Entered Element is 48 Unrolled Linked List = 90 3 12 43 88 94 15 7 67 74 85 48
Time complexity : O(n)
Also, few real world applications :
- It is used in B-Tree and T-Tree
- Used in Hashed Array Tree
- Used in Skip List
- Used in CDR Coding
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Unrolled Linked List | Set 1 (Introduction)
- Insertion Sort for Singly Linked List
- Circular Singly Linked List | Insertion
- Recursive insertion and traversal linked list
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Insertion in a sorted circular linked list when a random pointer is given
- Insertion at Specific Position in a Circular Doubly Linked List
- Create new linked list from two given linked list with greater element at each node
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular linked list
- Merge a linked list into another linked list at alternate positions
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Skip List | Set 2 (Insertion)
- Convert Singly Linked List to XOR Linked List
- Check if a linked list is Circular Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Construct a Doubly linked linked list from 2D Matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : 29AjayKumar