Iterated Logarithm log*(n)

08 Dec, 2021
Iterated Logarithm or Log*(n) is the number of times the logarithm function must be iteratively applied before the result is less than or equal to 1.
 
Applications: It is used in the analysis of algorithms (Refer Wiki for details)
C++
Java
Python3
C#
PHP
Javascript
// Recursive CPP program to find value of// Iterated Logarithm#include <bits/stdc++.h>using namespace std; int _log(double x, double base){    return (int)(log(x) / log(base));} double recursiveLogStar(double n, double b){    if (n > 1.0)        return 1.0 + recursiveLogStar(_log(n, b), b);    else        return 0;} // Driver codeint main(){    int n = 100, base = 5;    cout << "Log*(" << n << ") = "         << recursiveLogStar(n, base) << "\n";    return 0;}
// Recursive Java program to// find value of Iterated Logarithmimport java.io.*; class GFG{static int _log(double x,                double base){    return (int)(Math.log(x) /                 Math.log(base));} static double recursiveLogStar(double n,                               double b){    if (n > 1.0)        return 1.0 +               recursiveLogStar(_log(n,                                 b), b);    else        return 0;} // Driver codepublic static void main (String[] args){    int n = 100, base = 5;    System.out.println("Log*(" + n + ") = " +                  recursiveLogStar(n, base));}} // This code is contributed by jit_t
# Recursive Python3 program to find value of# Iterated Logarithmimport math def _log(x, base):     return (int)(math.log(x) / math.log(base)) def recursiveLogStar(n, b):     if(n > 1.0):        return 1.0 + recursiveLogStar(_log(n, b), b)    else:        return 0  # Driver codeif __name__=='__main__':    n = 100    base = 5    print("Log*(", n, ") = ", recursiveLogStar(n, base)) # This code is contributed by# Sanjit_Prasad
// Recursive C# program to// find value of Iterated Logarithm using System; public class GFG{static int _log(double x, double baset){    return (int)(Math.Log(x) /                Math.Log(baset));} static double recursiveLogStar(double n,                            double b){    if (n > 1.0)        return 1.0 +            recursiveLogStar(_log(n,                                b), b);    else        return 0;} // Driver code    static public void Main (){         int n = 100, baset = 5;    Console.WriteLine("Log*(" + n + ") = " +                recursiveLogStar(n, baset));}} // This code is contributed by ajit.
<?php// Recursive PhP program to find// value of Iterated Logarithm function _log($x, $base){    return (int)(log($x) / log($base));} function recursiveLogStar($n, $b){    if ($n > 1.0)        return 1.0 +               recursiveLogStar(_log($n,                               $b), $b);    else        return 0;} // Driver code$n = 100; $base = 5;echo "Log*(" , $n , ")"," = ",recursiveLogStar($n, $base), "\n"; // This code is contributed by ajit?>
<script> // Javascript program to// find value of Iterated Logarithm     function _log( x, base){    return (Math.log(x) /                 Math.log(base));}  function recursiveLogStar(n, b){    if (n > 1.0)        return 1.0 +               recursiveLogStar(_log(n,                                 b), b);    else        return 0;}     // Driver code     let n = 100, base = 5;    document.write("Log*(" + n + ") = " +                  recursiveLogStar(n, base));         // This code is contributed by sanjoy_62.</script>
Output : 
Log*(100) = 2
Iterative Implementation : 
C++
Java
Python3
C#
Javascript
// Iterative CPP function to find value of// Iterated Logarithmint iterativeLogStar(double n, double b){    int count = 0;    while (n >= 1) {        n = _log(n, b);        count++;    }    return count;}
// Iterative Java function to find value of// Iterated Logarithmpublic static int iterativeLogStar(double n, double b){    int count = 0;    while (n >= 1) {        n = _log(n, b);        count++;    }    return count;} // This code is contributed by pratham76
# Iterative Python function to find value of# Iterated Logarithm  def iterativeLogStar(n, b):     count = 0    while(n >= 1):        n = _log(n, b)        count = count + 1     return count # This code is contributed by# Sanjit_Prasad
// Iterative C# function to find value of// Iterated Logarithmstatic int iterativeLogStar(double n, double b){    int count = 0;    while (n >= 1)    {        n = _log(n, b);        count++;    }    return count;} // This code is contributed by rutvik_56
<script> // Iterative javascript function to find// value of Iterated Logarithmfunction iterativeLogStar(n, b){    var count = 0;    while (n >= 1)    {        n = _log(n, b);        count++;    }    return count;} // This code is contributed by 29AjayKumar </script>
This article is contributed by Abhishek rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 
jit_t
Sanjit_Prasad
rutvik_56
pratham76
sanjoy_62
29AjayKumar
Analysis
Mathematical
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.