This question evaluates understanding of tree data structures and the lowest common ancestor concept, contrasting use of binary search tree ordering with the general binary tree case while requiring algorithmic time and space complexity reasoning in the Coding & Algorithms domain.
You are given the root of a binary search tree (BST) and two distinct nodes p and q that are guaranteed to exist in the tree.
Task (BST case):
Assumptions:
Follow-up:
Describe algorithms for both the BST and the general binary tree cases and analyze their time and space complexity.