Question: Imagine that you work for a database company, which has a popular system for maintaining sorted sets. After a negative review in an influential technology
Imagine that you work for a database company, which has a popular system for maintaining sorted sets. After a negative review in an influential technology website, the company has decided it needs to convert all of its indexing software from using sorted arrays to an indexing strategy based on using binary search trees, so as to be able to support insertions and deletions more efficiently. Your job is to write a program that can take a sorted array, A, of n elements, and construct a binary search tree, T, storing these same elements, so that doing a binary search for any element in T will run in O(log n) time. Describe an O(n)-time algorithm for doing this conversion.
Step by Step Solution
3.37 Rating (163 Votes )
There are 3 Steps involved in it
Take the element at An2 and place it at the root r of T Then re... View full answer
Get step-by-step solutions from verified subject matter experts
