Javatpoint Logo
Javatpoint Logo

Self-organizing List

A self-organizing list serializes its elements to optimize mean access time using a self-organizing algorithm. A self-organizing list aims to make linear search more efficient by pushing frequently accessed items to the front of the list. In the best situation, a self-organizing list achieves near-constant time for element access.

A reorganizing method is used by a self-organizing list to adjust to different query distributions at runtime. While key-value ordering is the most frequent method for sorting lists, it is not the only one. Another way to organize lists to speed up searches is to sort them by expected access frequency. While the benefits may not be as substantial as when ordered by key value, organizing (at least roughly) by frequency of access can be much less expensive and speed up sequential search in some cases.

A sorted linked list's worst-case search time is O. (n). After one comparison with root, we can skip roughly half of the nodes with a Balanced Binary Search Tree. We have random access to a sorted array and can use Binary Search on arrays.

Self-organizing lists rearrange the records in the list according to the actual pattern of record access. For determining how to arrange the list, self-organizing lists employ a heuristic. These heuristics are comparable to buffer pool management guidelines. A buffer pool is, in reality, a type of self-organizing list. Because we normally must explore the contents of the buffers to determine if the needed information is already in the main memory, ordering the buffer pool by expected frequency of access is a suitable method.

When ordered by frequency of access, the buffer at the end of the list will be the most suited for reuse when a fresh page of information needs to be read. For managing self-organizing lists, there are three traditional heuristics. These three heuristics are listed below:

1. Frequency Count

One of the most obvious techniques to keep a list ordered by frequency is to keep track of how many times each record has been accessed and keep the records in that order at all times. Frequency count, or simply "count," will be the name of this procedure. The count is a buffer replacement approach that isn't utilized very often. If the number of accesses to a record exceeds the number of accesses to a record preceding it, the record will advance to the head of the list. As a result, the count will keep track of the records in the order in which they've happened so far.

The count does not respond well to the increasing frequency of access over time and requires space for access counts. A big number of people can access a record once it's been accessed. In addition to requiring space for access counts, the count does not respond well to increasing access frequency over time. Regardless of subsequent access history, once a record has been accessed a significant number of times under the frequency count system, it will remain near the top of the list.

2. Transpose

Any record found should be swapped with the record in the list that comes before it. Transpose is the name for this strategy. For list implementations that use linked lists or arrays, Transpose is a viable choice. Records that are used frequently will get to the top of the list over time. Records that were once frequently accessible but are no longer needed will gradually be pushed to the back of the file cabinet. As a result, it appears to have favorable features in terms of changing access frequency. Unfortunately, some access sequences are pathological and can cause transposition to fail.

Consider the situation in which the list's last record (called XX) is accessed. The next-to-last record (say YY) is then swapped out with this one. The next-to-last record (say YY) is then exchanged with this one, making YY the final record. If YY is now accessible, it will be replaced with XX. Because neither record will ever progress toward the front, a repeating series of accesses alternating between XX and YY will always search to the end of the list. In practice, however, such pathological situations are uncommon. Moving the accessed record forward in the list by a fixed number of steps is a variation on transposition.

3. Move to Front

It is moved to the top of the list when a record is located, pushing all other records back to one spot. The move-to-front strategy is equivalent to the most recently utilized buffer replacement strategy. If the records are stored in a linked list, this heuristic is simple to apply. When records are stored in an array, moving a record forward from near the end causes many records to (slightly) shift positions.

When at least n searches are conducted, the cost of move-to-front is finite because it requires at most twice the number of accesses required by the optimal static ordering for n records. In other words, if we had known the sequence of (at least n) searches ahead of time and stored the data in order of frequency to reduce the total cost of these accesses, the cost would have been at least half of what the move-to-front heuristic required. (Amortized analysis can be used to verify this).

Finally, move-to-front adapts to local variations in access frequency, so if a record is often accessed for a short time, it will appear near the front of the list during that time. When records are processed sequentially, move-to-front performs badly, especially if the sequential order is repeated numerous times.

Java Code

Now let's write a Java code to perform all the basic operations on a Self-organizing List Data structure.

Output:

The above code gives the following output.

Enter the size of Self Organizing List::
10
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
1
Enter integer element to insert
101

List = 101 
Count = 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
1
Enter integer element to insert
102

List = 101 102 
Count = 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
1
Enter integer element to insert
103

List = 101 102 103 
Count = 0 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
1
Enter integer element to insert
104

List = 101 102 103 104 
Count = 0 0 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
3
Enter integer element to search
102
Search Result : true

List = 102 101 103 104 
Count = 1 0 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
3
Enter integer element to search
104
Search Result : true

List = 102 104 101 103 
Count = 1 1 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
2
Enter position to delete
104
Invalid position 

List = 102 104 101 103 
Count = 1 1 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
2
Enter position to delete
2

List = 102 101 103 
Count = 1 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
4
Empty status = false

List = 102 101 103 
Count = 1 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
5
Full status = false

List = 102 101 103 
Count = 1 0 0 
Do you want to continue (Type y or n) 

y
Please Choose one of the Operations::
1. To insert Data in the Self Organizing List.
2. To delete Data from the Self Organizing List.
3. To search/find Data in the Self Organizing List.
4. To Check List is empty or not.
5. To Check List is full or not.
6. To Get the size of the Self Organizing List.
6
Size = 3 


List = 102 101 103 
Count = 1 0 0 
Do you want to continue (Type y or n) 

n

Advantages of Self-organizing List

A self-organizing list has the following advantages, such as:

  • During the compilation or interpretation of program source code, language translators such as compilers and interpreters use self-organizing lists to maintain symbol tables.
  • Embedded systems are currently undergoing research to incorporate the self-organizing list data format to reduce bus transition activity, which causes power consumption in those circuits.
  • Artificial intelligence and neural networks, as well as self-adjusting systems, utilize these lists. As in the case of the LFU algorithm, the methods used in self-organizing lists are also used as caching algorithms.

In real-world collections, the basic Move to Front and transposition methods can be used to organize a spice drawer by moving used items to the front of the drawer or to transpose a cleaning item with its front-most neighbor when it is used.







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