VOOZH about

URL: https://www.geeksforgeeks.org/dsa/insertion-unrolled-linked-list/

⇱ Insertion in Unrolled Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Insertion in Unrolled Linked List

Last Updated : 31 Jan, 2023

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. 

Algorithm : 

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

Implementation: Following is the Java implementation of the insertion and display operation. In the below code, the capacity is 5 and random numbers are input. 


Output
Entered Element is 67

Unrolled Linked List = 
67 

Entered Element is 69

Unrolled Linked List = 
67 69 

Entered Element is 50

Unrolled Linked List = 
67 69 50 

Entered Element is 60

Unrolled Linked List = 
67 69 50 60 

Entered Element is 18

Unrolled Linked List = 
67 69 50 60 18 

Entered Element is 15

Unrolled Linked List = 
67 69 50 
60 18 15 

Entered Element is 41

Unrolled Linked List = 
67 69 50 
60 18 15 41 

Entered Element is 79

Unrolled Linked List = 
67 69 50 
60 18 15 41 79 

Entered Element is 12

Unrolled Linked List = 
67 69 50 
60 18 15 
41 79 12 

Entered Element is 95

Unrolled Linked List = 
67 69 50 
60 18 15 
41 79 12 95 

Entered Element is 37

Unrolled Linked List = 
67 69 50 
60 18 15 
41 79 12 95 37 

Entered Element is 13

Unrolled Linked List = 
67 69 50 
60 18 15 
41 79 12 
95 37 13 

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
Comment