Self Organizing List : Move to Front Method
Self Organizing list is a list that re-organizes or re-arranges itself for better performance. In a simple list, an item to be searched is looked for in a sequential manner which gives the time complexity of O(n). But in real scenario not all the items are searched frequently and most of the time only few items are searched multiple times.
So, a self organizing list uses this property (also known as locality of reference) that brings the most frequent used items at the head of the list. This increases the probability of finding the item at the start of the list and those elements which are rarely used are pushed to the back of the list.
In Move to Front Method, the recently searched item is moved to the front of the list. So, this method is quite easy to implement but it also moves in-frequent searched items to front. This moving of in-frequent searched items to the front is a big disadvantage of this method because it affects the access time.
Input : list : 1, 2, 3, 4, 5, 6 searched: 4 Output : list : 4, 1, 2, 3, 5, 6 Input : list : 4, 1, 2, 3, 5, 6 searched : 2 Output : list : 2, 4, 1, 3, 5, 6
List: 1 --> 2 --> 3 --> 4 --> 5 Searched: 4 List: 4 --> 1 --> 2 --> 3 --> 5 Searched: 2 List: 2 --> 4 --> 1 --> 3 --> 5
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.