Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2009 Curt Hill Self Organizing Lists Another form of searchable list.

Similar presentations


Presentation on theme: "Copyright © 2009 Curt Hill Self Organizing Lists Another form of searchable list."— Presentation transcript:

1 Copyright © 2009 Curt Hill Self Organizing Lists Another form of searchable list

2 Normal Searched Lists Unlike an array, a list cannot be searched by a binary search A list is sorted only so that search can quit early It is thus it is largely an O(N) activity Since there are plenty of better searches that are O(log N) or better a list is seldom a good choice Copyright © 2009 Curt Hill

3 Self organizing lists Instead of sorting by key, sort by frequency Drive frequently used items to the front of the list and seldom accessed items to the back of the list A self organizing list modifies itself based on accesses Do this without prior information as to how frequently an item will be accessed –These lists may be kept in either vectors or lists Only uses a sequential search technique Copyright © 2009 Curt Hill

4 How? Several techniques Keep a count of accesses Move each item accessed to the front Move each item closer to the front Copyright © 2009 Curt Hill

5 Counts Keep a count of accesses in each record Keep the list sorted by this number of accesses At the beginning the list has no accesses so all counts are zero and hence any order is acceptable Each search then increments the count of just one item Copyright © 2009 Curt Hill

6 Counts Again Incrementing the count does not provoke a full sort of the list Rather you just move that item forward until its count is larger than the next and smaller than the prior The disadvantage of this approach –Extra storage in the list for the count Once a large number of accesses have occurred things do not move very far Copyright © 2009 Curt Hill

7 More on counts A number of accesses to an item in a short time normally moves the item –If that number of accesses is small compared to the total number it will not move item very far At the end of the run the list has the optimal static order Possible to save this or a variant of this for next time –Either save the exact counts or the counts divided by some constant Copyright © 2009 Curt Hill

8 Move to front Each accessed item becomes the first item in the list –At least until the next access Push all subsequent items down a slot Compare this to caching This works much better for lists than vectors since insertion in a list is painless while insertion in a list is painful Copyright © 2009 Curt Hill

9 Move to Front There is a pathlogically bad case where we always reference the last item –This case is extremely unlikely We typically use self-organizing lists where we have very few items that are very frequently used Copyright © 2009 Curt Hill

10 Transposition Every time a record is accessed swap it with the item before it Frequently used items will migrate toward the front and seldom used ones will move toward the back One item never changes the list much Modification: If this is an array you may want to swap the item with something closer to the front, such as halfway to the front rather than move it just one slot Copyright © 2009 Curt Hill

11 Example –1 is 30% –1 is 25% –1 is 20% –1 is 5% –1 is 4% –1 is 3% –2 are 2% –1 is 1.5% –1 is 1% –5 are.5% –2 are.3 % –4 are.2% –23 are.1% –6 arr.05% Copyright © 2009 Curt Hill A list of 50 items with widely differing frequencies.

12 Do the math Assume that the self-organizing list achieves optimal static order –The first three items account for 75% of the searches The average searches is the sum of the frequency times the position divided by total searches In this case the average search length is An log 2 N search would give a length of Copyright © 2009 Curt Hill

13 Frequency Distribution Copyright © 2009 Curt Hill

14 Summary Self-organizing lists need a radical frequency distribution to be effective against O(log 2 N) searches –Such as a binary or tree search A failure has to search entire list, so these should be infrequent as well Like perfect hashes these need to be looked for Very good search when conditions are right Copyright © 2009 Curt Hill


Download ppt "Copyright © 2009 Curt Hill Self Organizing Lists Another form of searchable list."

Similar presentations


Ads by Google