Solution: Find Ancestors of a Given Node in a BST
Explore recursive and iterative solutions to find all ancestors of a given node in a binary search tree (BST). Understand how to traverse the BST efficiently while tracking the path to the target node. Learn the complexities and implement these techniques in C++ to strengthen your tree algorithm skills for coding interviews.
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.