In a scientific application I’m writing (vb.net) I use a huge collection of object stored in a tree structure. Every object exposes a LastAccessed property (datetime) that stores the last time the node was accessed by the algorithm.
I need to find a fast way to find the N least accessed objects in the structure.
I’m using an algorithm like this (pseudo-code)
dim Olist as new list (of myobject)
....
array.sort(Olist,address of compareByDataReverse)
for index=0 to N-1
dosomething(Olist.item(index))
end
I’m sure there is a better way to do that because the list is normally huge ( consisting of more than 10^6 objects).
Thanks
Pierluigi
in best case your code will perform with O(nlogn). You should begin with
dim Olist as new list (of myobject)then take a LinkedList and go over your collection and add values to your list keeping it sorted. This will be O(n*m)