← 返回 databricks 的题目列表Construct a Fibonacci Tree and Analyze Time Complexity
类型:online_judge
Problem: Construct a Fibonacci Tree and Analyze Time Complexity
Given an integer n, define a Fibonacci Tree recursively as follows:
If n = 0 or n = 1, the tree is a single node with value n.
If n > 1, the root has value n, its left subtree is FibTree(n-1), and its right subtree is FibTree(n-2).
Tasks
Write/describe a recursive algorithm to construct this Fibonacci Tree.
Analyze the time complexity of the construction (Big-O) and justify it.
Constraints
0 <= n <= 30 (for complexity discussion; not necessarily to actually build huge trees).
Example (shape)
n = 3: root is 3, left subtree is FibTree(2), right subtree is FibTree(1).
Example
Input
0
Output
(single node tree with value 0)