Created
May 3, 2014 22:14
-
-
Save unixpickle/714bdf2e1dc992d4daaa to your computer and use it in GitHub Desktop.
Calculate b-tree size
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
# Take a binary tree of depth D, where the lowest nodes have 1 bit, the second lowest have 2 bits, etc. | |
# This script finds the number of bits in a tree of depth D. | |
if process.argv.length isnt 3 | |
console.log 'Usage: coffee calc.coffee <depth>' | |
process.exit() | |
depth = parseInt process.argv[2] | |
count = 0 | |
for i in [0...depth] | |
count += Math.pow(2, i) * (depth - i) | |
console.log "there are #{count} bits" | |
regularNum = (1 << depth) - 1 | |
console.log "this is #{100*count/regularNum}% the b-tree size" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment