Created
June 30, 2018 22:45
-
-
Save joriki/6a1e36f4de7118076a26c423200780e6 to your computer and use it in GitHub Desktop.
Calculate the expected number of elements in a rooted ordered unlabeled binary tree of maximum depth d; see https://math.stackexchange.com/questions/2836730
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
public class Question2836730 { | |
public static void main (String [] args) { | |
BigInteger a = BigInteger.ONE; | |
BigInteger s = BigInteger.ZERO; | |
for (int d = 1;;d++) { | |
BigInteger square = a.multiply (a); | |
BigInteger sn = s.multiply (a).multiply (BigInteger.TWO).add (square); | |
BigInteger an = square.add (BigInteger.ONE); | |
BigInteger ds = sn.subtract (s); | |
BigInteger da = an.subtract (a); | |
double mean = ds.doubleValue () / da.doubleValue (); | |
System.out.println (d + "&" + sn.doubleValue () / an.doubleValue () + "&" + mean + "&" + (mean + 1) / Math.pow (2,d) + "\\\\"); | |
a = an; | |
s = sn; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment