What is O(log* N)?

前端 未结 3 1524
南旧
南旧 2020-12-07 11:53

What is O(log* N) and how is it different from O(log N)?

相关标签:
3条回答
  • 2020-12-07 12:35

    O( log* N ) is "iterated logarithm":

    In computer science, the iterated logarithm of n, written log* n (usually read "log star"), is the number of times the logarithm function must be iteratively applied before the result is less than or equal to 1.

    0 讨论(0)
  • 2020-12-07 12:49

    The log* N bit is an iterated algorithm which grows very slowly, much slower than just log N. You basically just keep iteratively 'logging' the answer until it gets below one (E.g: log(log(log(...log(N)))), and the number of times you had to log() is the answer.

    Anyway, this is a five-year old question on Stackoverflow, but no code?(!) Let's fix that - here's implementations for both the recursive and iterative functions (they both give the same result):

    public double iteratedLogRecursive(double n, double b)
    {
        if (n > 1.0) {
            return 1.0 + iteratedLogRecursive( Math.Log(n, b),b );
        }
        else return 0;
    }
    
    public int iteratedLogIterative(double n, double b)
    {
        int count=0;
        while (n >= 1) {
            n = Math.Log(n,b);
            count++;
        }
        return count;
    }
    
    0 讨论(0)
  • 2020-12-07 12:51

    log* (n)- "log Star n" as known as "Iterated logarithm"

    In simple word you can assume log* (n)= log(log(log(.....(log* (n))))

    log* (n) is very powerful.

    Example:

    1) Log* (n)=5 where n= Number of atom in universe

    2) Tree Coloring using 3 colors can be done in log*(n) while coloring Tree 2 colors are enough but complexity will be O(n) then.

    3) Finding the Delaunay triangulation of a set of points knowing the Euclidean minimum spanning tree: randomized O(n log* n) time.

    0 讨论(0)
提交回复
热议问题