Solution: Find Ancestors of a Given Node in a BST
Explore techniques to identify all ancestors of a target node in a binary search tree by applying both recursive and iterative traversal methods. Understand how to implement these solutions in Python, analyze their time and space complexities, and gain confidence in solving tree-based interview problems.
Statement
Given the root node of a binary search tree (BST) and an integer value k, find all the ancestors of the node whose value is k.
An ancestor of a node in a tree is any node on the path from the root to that node.
Constraints:
Let n be the number of nodes in a binary search tree.