Find the numbers present at Kth level of a Fibonacci Binary Tree | Initializing the max value ; Array to store all the fibonacci numbers ; Function to generate fibonacci numbers using Dynamic Programming ; 0 th and 1 st number of the series are 0 and 1 ; Add the previous two numbers in the series and store it ; Function to print the Fibonacci numbers present at Kth level of a Binary Tree ; Finding the left and right index ; Iterating and printing the numbers ; Precomputing Fibonacci numbers
var MAX_SIZE = 100005 ; var fib = Array ( MAX_SIZE + 1 ) . fill ( 0 ) ; function fibonacci ( ) { var i ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( i = 2 ; i <= MAX_SIZE ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } function printLevel ( level ) { var left_index = parseInt ( Math . pow ( 2 , level - 1 ) ) ; var right_index = parseInt ( ( Math . pow ( 2 , level ) - 1 ) ) ; for ( i = left_index ; i <= right_index ; i ++ ) { document . write ( fib [ i - 1 ] + " " ) ; } document . write ( ) ; } fibonacci ( ) ; var K = 4 ; printLevel ( K ) ;