Created
September 10, 2010 13:53
-
-
Save jesjos/573661 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Run { | |
public static void main(String [] args) { | |
Skipcheck skip = new Skipcheck(100000000); | |
skip.tester(); | |
} | |
} |
This file contains hidden or 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.util.ArrayList; | |
class Skipcheck { | |
// Maximum column height in test | |
private int ceiling; | |
// Constructor | |
public Skipcheck (int c) { | |
ceiling = c; | |
} | |
// Frequency function for Hn, k is the height that we're calculating the probability for | |
// nis the number of nodes in the beginning | |
private double f (double k, double n) { | |
return Math.pow(1 - Math.pow(0.5,(k+1)),n) - Math.pow(1 - Math.pow(0.5,k),n); | |
} | |
// Calculates the expected value for Hn, given that n = 2^i, k = ceiling for column height | |
private double E (double i, int k) { | |
double j = Math.pow (2,i); | |
double sum = 0; | |
for (double x = k; x >= 0; x--) { | |
sum += x*f(x,j); | |
} | |
return sum; | |
} | |
public void tester () { | |
for (int iterator = 1; iterator <= 7; iterator++) { | |
System.out.println(E(iterator,ceiling)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment