Question
Consider a Binary Search Tree (BST) where every node
stores a key and two child pointers. What is the time complexity of finding the Lowest Common Ancestor (LCA) of two nodes in a balanced BST with n nodes?ÂSolution
The time complexity of finding the LCA in a balanced BST is O(log n). A Binary Search Tree (BST) ensures that, for every node, all values in its left subtree are smaller, and all values in its right subtree are larger. To find the LCA of two nodes, you can perform a binary search, comparing the node values with the LCA candidates and traversing left or right subtrees based on comparisons. As the height of a balanced BST is log n, finding the LCA involves a traversal that follows the height of the tree, thus resulting in a time complexity of O(log n). Why Other Options are Incorrect: A) O(n): This is the time complexity of finding the LCA in an unbalanced BST, not a balanced one. C) O(n log n): This time complexity is typically associated with certain sorting algorithms, not BST operations. D) O(1): This is incorrect because finding the LCA requires traversal in a balanced BST. E) O(n² ): This time complexity is associated with certain algorithms in dynamic programming, not for BST operations.
Identify the top 3 countries in the 2024 International Mathematical Olympiad (IMO)?
According to the IMF, which reform area is crucial for sustaining India’s growth?
What was the objective of Exercise Poorvi Lehar conducted by the Indian Navy on the East Coast?
The food ministry has estimated the cost of Smart PDS scheme- launched to create an integrated national-level dashboard for monitoring of end-to-end ope...
Which Indian athlete won India’s only gold medal in the Men’s Heptathlon at the Asian Indoor Athletics Championships 2026 with 5993 points?
Under the MoU (PM VIKAS-linked) to be signed in Kerala, how many total candidates from minority communities will be trained?
Consider the following statements:
I. For the purpose of effective utilization of Remote Sensing and Geographic Information System technology (GI...
Security Printing and Minting Corporation of India Limited (SPMCIL) has set up ‘new banknote printing lines’ at its Currency Note Press, Nashik and...
As per the Periodic Labour Force Survey (PLFS) for July–September 2025, what was the unemployment rate among females in urban areas?
In 2024, which landmark did the Angara-A5 rocket achieve during its test flight from the Vostochny Cosmodrome?