You need the smallest actual frequency, which, I think, cannot be determined without sorting the actual frequencies. If the only thing you have is the Fenwick tree, then you can calculate the sequence of actual frequencies in O (n * log (n)) time (since you can calculate each individual actual frequency in O (log (n)) (see here ) and you have n frequencies). Sorting a sequence of actual frequencies with quicksort takes O (n * log (n)) , and finding the k-th element of the sorted sequence takes O (n) (maybe records with the same actual frequency, so you cannot do this in O (1 ), but you can use linear search). Thus, the entire search can be performed in O (n * log (n)).
Hope this helps. I do not know how this can be done in O (k * log (n)).
source share