Count Balanced Binary Trees of Height h | Javascript program to count number of balanced binary trees of height h . ; base cases ; Driver program
let MOD = 1000000007 ; function countBT ( h ) { let dp = new Array ( h + 1 ) ; dp . fill ( 0 ) ; dp [ 0 ] = 1 ; dp [ 1 ] = 1 ; for ( let i = 2 ; i <= h ; ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ; return dp [ h ] ; } let h = 3 ; document . write ( " " + countBT ( h ) ) ;