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
MAX_SIZE = 100005 NEW_LINE fib = [ 0 ] * ( MAX_SIZE + 1 ) NEW_LINE def fibonacci ( ) : NEW_LINE INDENT fib [ 0 ] = 0 NEW_LINE fib [ 1 ] = 1 NEW_LINE for i in range ( 2 , MAX_SIZE + 1 ) : NEW_LINE INDENT fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] NEW_LINE DEDENT DEDENT def printLevel ( level ) : NEW_LINE INDENT left_index = pow ( 2 , level - 1 ) NEW_LINE right_index = pow ( 2 , level ) - 1 NEW_LINE for i in range ( left_index , right_index + 1 ) : NEW_LINE INDENT print ( fib [ i - 1 ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT fibonacci ( ) NEW_LINE K = 4 NEW_LINE printLevel ( K ) NEW_LINE