Question
What is the time complexity of searching an element in
a balanced binary search tree (BST) with nnn nodes?Solution
In a balanced binary search tree (BST) , the height of the tree is maintained as O(log n)), ensuring that each level of the tree splits the search space roughly in half. This property allows searching for an element in the tree with logarithmic time complexity. For example, consider a balanced BST with 15 nodes. The height is approximately log 215≈4, so searching for any element will involve checking at most 4 nodes from the root to a leaf. The logarithmic reduction at each step (halving the search space) makes this approach efficient for large datasets. Balanced trees such as AVL or Red-Black trees maintain this logarithmic height through rotation operations during insertion and deletion, ensuring the O(log n) search time even after multiple modifications. Explanation of Incorrect Options: A) O(n) : This would be the time complexity for searching in an unbalanced BST or a linked list, where all nodes are skewed to one side. However, a balanced BST ensures O(log n) complexity. C) O(n2) This complexity is not applicable to BST search operations. It might appear in poorly optimized nested loops or certain pathological cases in other algorithms. D) O(1) Constant time search is achieved in hash tables, not in BSTs, as BSTs require traversing nodes to locate the target element. E) O(nlog n) This is the complexity of sorting algorithms like Merge Sort or Heap Sort, not searching in a BST.
Three of the following four figure pairs are alike in a certain way and thus form a group. Which is the one that does not belong to that group?
<...
If TOUR is written as 1234, CLEAR is written as 56784 and SPARE is written as 90847, find the code for CARE
Select the set in which the numbers are related in the same way as are the numbers of the given sets.
(213, 157), (185, 129)
(NOTE : Opera...
Five towns A, B, C, D and E are visited by a person from Monday to Friday. On each day the person visits only one town. The person visits A on Monday. H...
Based on the English alphabetical order, three of the following four letter-clusters are alike in a certain way and thus form a group. Which is the one ...
An Assertion (A) and a Reason (R) are given below.
Assertion (A): The Indian Constitution came into force with effect from 26th January 1950.
Which of the following terms will replace the question mark (?) in the given series?
MFT, NIS, PLQ, SON, WRJ, ?
In the following question, some symbols are represented by letters as shown below: 'G' means +, 'H' means -, 'M' means ×, 'J' means ÷, 'K' means =. Wh...
Among five persons Sunny, Swati, Somya, Surbhi and Sapna; Swati was elder to Somya but younger to Sunny. Surbhi was elder to Sunny who was just elder to...
Select the set in which the numbers are related in the same way as are the numbers of the following sets.
(NOTE: Operations should be performed o...