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.
If a nine-digit number 785x3678y is divisible by 72, then the value of (x − y) is:
Which of the following numbers is divisible by 22?
When a number is divided by 25, the quotient is 140, and the difference between the quotient and the remainder is 126. Find the number.
Which of the following numbers is divisible by 11?
What will be the remainder when 577 + 87 is divided by 13?
A six-digit number 11p9q4 is divisible by 24. Then the greatest possible value for (p + q) is
If 'x' is the lowest positive integer divisible by 16, 18 and 20, then find the second smallest positive integer which is divisible by all the three gi...
Which of the following numbers is divisible by 11?
A number n when divided by 6, leaves a remainder of 3. What will be the remainder when (n² +5n+8) is divided by 6?
Which of the following numbers is divisible by 11?