I hope someone can help, I'm not a programmer, but I was interested in learning the Fibonacci sequence and the recursive tree ...
I created the Binary Tree class along with its associated TreeNode class and want to generate a binary tree of recursive calls created:
f (n) = f (n-1) + f (n-2) for a given value of n
I would like to add it as the InsertFibonacci method of my binary tree, replacing the standard Insert method:
def insertNode(self, root, inputData): if root == None: return self.addNode(inputData) else: if inputData <= root.nodeData: root.left = self.insertNode(root.left, inputData) else: root.right = self.insertNode(root.right, inputData) return root
Did I add something from the decorator to the Fib function?
# Fib function def f(n): def helper(n): left = f(n-1) right = f(n-2) return left,right if n == 0: return 0 elif n == 1: return 1 else: left, right = helper(n) return left + right
source share