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.
In which of the following cases has the Supreme Court observed that the issue of limitation is a jurisdictional issue which should be decided by the ar...
Chapter III of the Transfer of Property Act, 1882 deals with-
...According to the Bhartiya Nagarik Suraksha Sanhita, what does "investigation" include________________
Supremacy of Law is the first meaning of Rule of Law was established by?
Under the Competition Act, 2002 the definition of Public Financial Institution does not include__________
As per Payment of Wages Act in factory,_______________shall be liable to pay  wages to employee employed.
Any penalty may be imposed or any confiscation may be adjudged under the Foreign Trade (Development and Regulation) Act by_____
The first meeting of the committee of creditors shall be held within seven days of the_______________
When a property liable to be attached is subjected to execution of decree in 2 courts the court which shall realise it first shall be_________.
Which section of the Contract Ac delas with the provisions of effect of neglect of promisee to afford promisor reasonable facilities for performance?