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.
A train moving at 72 km/h takes 20 seconds to pass a pole. Find the time required for the train to cross a platform that is 0.6 times the length of the ...
Two cars start from a place with a speed of 45 km/hr at an interval of 10 minutes. What is the speed of a man coming from the opposite direction towards...
- Two cars ‘C’ and ‘D’ started from places ‘L’ and ‘M’ towards each other at the same time. When they crossed after 10 hours, car ‘D’ had...
A train 500 m long running at 108 km/hr takes 40 seconds to cross a bridge. The length of the bridge is
Two trains 175 metres and 125 metres in length are running towards each other on parallel tracks, one at the rate 55 km/hr and another at 35 km/hr. In h...
A 160 m long train crosses another 280 m long train running in the opposite direction in 11 seconds. If the shorter train crosses a pole in 8 seconds, w...
Two trains of equal lengths take 15 seconds and 30 seconds respectively to cross a telegraph post. If the length of each train be 120 metres, in what ti...
Train A. running at the speed of 80 km/hr crossed train B. running at the speed of 70 km/hr in the opposite direction. Both trains finish crossing each ...
Ratio of the lengths of two trains ‘X’ and ‘Y’ is 5:6 respectively and the ratio of time taken by them to cross a pole is 3:4 respectively. If s...
- A train of 175 metres is running at a speed of 72 km/h and crosses a platform in 36 seconds. Determine the length of the platform.