Count Balanced Binary Trees of Height h | PHP program to count number of balanced ; base cases ; Driver Code
< ? php $ mod = 1000000007 ; function countBT ( $ h ) { global $ mod ; $ dp [ 0 ] = $ dp [ 1 ] = 1 ; for ( $ i = 2 ; $ i <= $ h ; $ i ++ ) { $ dp [ $ i ] = ( $ dp [ $ i - 1 ] * ( ( 2 * $ dp [ $ i - 2 ] ) % $ mod + $ dp [ $ i - 1 ] ) % $ mod ) % $ mod ; } return $ dp [ $ h ] ; } $ h = 3 ; echo " No . ▁ of ▁ balanced ▁ binary ▁ trees " , " ▁ of ▁ height ▁ h ▁ is : ▁ " , countBT ( $ h ) , " STRNEWLINE " ; ? >