Skip to content

Instantly share code, notes, and snippets.

@bssstudio
Created January 24, 2013 10:06
Show Gist options
  • Select an option

  • Save bssstudio/4619496 to your computer and use it in GitHub Desktop.

Select an option

Save bssstudio/4619496 to your computer and use it in GitHub Desktop.
Expected number of subnodes of a randomly selected node in a tree.
def propab(d: Int, n: Int, b: Int): Double = {
Math.pow(b,d-1)/Math.pow(b,n)
}
def expected(n:Int, bf: Int): Double = {
(1 to n).foldLeft(0.0)( (a:Double,b:Int) => a + (b*propab(b,n,bf)) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment