Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looking for algorithm to calculate h-index fast

http://en.wikipedia.org/wiki/H-index

this wiki page is a definition of h-index

basically if I were to have an array of [ 0 3 4 7 8 9 10 ], my h-index would be 4 since I have 4 numbers bigger than 4. My h-index would've been 5 if I were to have 5 numbers bigger than 5, and etc. Given an array of integers bigger or equal to 0, what are the ways of calculating h-index efficiently?

edit: the array is not necessarily sorted

like image 838
cakester Avatar asked Nov 22 '13 07:11

cakester


People also ask

How do I manually calculate my h-index?

To manually calculate your h-index, organize articles in descending order, based on the number of times they have been cited. In the below example, an author has 8 papers that have been cited 33, 30, 20, 15, 7, 6, 5 and 4 times. This tells us that the author's h-index is 6.

How do I calculate my h-index?

Your h-index is based on a list of your publications ranked in descending order by the Times Cited count. The value of h is equal to the number of papers (N) in the list that have N or more citations.

How do you find the h-index in Python?

If we sort all the citations in decreasing order to sortlist, and index each citation number by 1, 2, 3, ..., then we can find the h-index is the max value i, which makes sortlist[i]>=i.


1 Answers

Here my realization O(N) with tabling, this is simple and blazing fast:

private static int GetHIndex(int[] m)
{
    int[] s = new int[m.Length + 1];
    for (int i = 0; i < m.Length; i++) s[Math.Min(m.Length, m[i])]++;

    int sum = 0;
    for (int i = s.Length - 1; i >= 0; i--)
    {
        sum += s[i];
        if (sum >= i)
            return i;
    }

    return 0;
}
like image 107
Толя Avatar answered Sep 18 '22 22:09

Толя