Given a k-th order Fibonacci tree represented by its pre-order traversal of node values, find the path between two given nodes. The challenge is to solve this without explicitly building the tree, using mathematical properties of Fibonacci trees to calculate node positions directly.
This problem tests your understanding of:
Fibonacci tree structure and mathematical properties
Tree traversal algorithms and their time complexity
Optimization techniques to avoid unnecessary tree construction
Lowest Common Ancestor (LCA) algorithms
A k-th order Fibonacci tree is defined recursively:
Order 0: Empty tree (0 nodes)
Order 1: Single node (1 node)
Order k (k >= 2): A tree with:
Root node
Left subtree: (k-1)-th order Fibonacci tree
Right subtree: (k-2)-th order Fibonacci tree
The number of nodes follows: T(k) = 1 + T(k-1) + T(k-2) with T(0)=0, T(1)=1.
This gives: T(1)=1, T(2)=2, T(3)=4, , , ...
Formula: A k-th order Fibonacci tree has exactly F(k+2) - 1 nodes, where F is the standard Fibonacci sequence (F(0)=0, F(1)=1, F(2)=1, F(3)=2, F(4)=3, F(5)=5...).
`
result = get_path(k=4, start=4, end=7)
`
1 <= k <= 45 (tree order)
Maximum nodes: T(45) = F(47) - 1 (approx 2.97 billion nodes)
1 <= start, end <= T(k) (valid node values in pre-order traversal)
Tree uses 1-based indexing for node values
All node values in the tree are unique