# Algorithm for most frequently used item?

• 07-20-2004
alphaoide
Algorithm for most frequently used item?
Basically I need the algorithm similar to WinXP start menu which display the most frequently used programs. Is there any common algorithm for that floating around the net? Just give me the algorithm name and I'll do my own research

• 07-20-2004
quzah
Yeah, we call it the for loop. ;)
Code:

```int array[SIZE]; /* fill array here... */ int x, highest; for( x = highest = 0; x < sizeof array / sizeof array[0]; x++ )     if( array[x] > array[highest] )         highest = x;```
Quzah.
• 07-20-2004
alphaoide
You want me to compare the count of each item has been used? It's not gonna work well because say I used a program 1000 times then it will take the other items 1001 to replace the most used.
• 07-20-2004
axon
why not have somekind of a search tree structure (AVL for example) where they key would be the item and the value would be frequency of use. You just have to figure out some tie braking method and you should be set.
• 07-20-2004
sean
Then only keep a record to a certain point. For example, don't allow any program to be counted as having been used more than say, 50 times. Or have each use time out after a certain number of days - but that would require a lot more disk space.
• 07-20-2004
alphaoide
Quote:

Originally Posted by sean_mackrory
Then only keep a record to a certain point. For example, don't allow any program to be counted as having been used more than say, 50 times.

Then after 50 times all items will have the same position.???

Quote:

Originally Posted by sean_mackrory
Or have each use time out after a certain number of days - but that would require a lot more disk space.

This one is what I've thought of the most. I have to reset something at some point.

*posibility 1* reset all items' counts after say, 3 days, but then on the fourth day I have to make sure to use old-most-used items so that they won't be replaced.

*posibility2* reset count of all items that haven't been used for the past 3 days. Sounds better, do you see any flaws?

*or maybe other possibilities?
• 07-20-2004
Thantos
Keep track of
1) The number of times used in the last X days
2) The last time it was used

If a program hasn't been used in Y days then consider it unused
If a program has a higher per day usage in the last Z days then another program it is ranked higher.
• 07-20-2004
alphaoide
Quote:

Originally Posted by Thantos
Keep track of
1) The number of times used in the last X days
2) The last time it was used

If a program hasn't been used in Y days then consider it unused
If a program has a higher per day usage in the last Z days then another program it is ranked higher.

Oh, sweet, I'll just implement this one, just perfect for my need.
Thanks