Building a balanced binary search tree

前端 未结 3 2001
南方客
南方客 2020-12-16 02:53

Is there a method to build a balanced binary search tree?

Example:

1 2 3 4 5 6 7 8 9

       5
      / \\
     3   etc
    / \\
   2   4
  /
 1
         


        
3条回答
  •  感情败类
    2020-12-16 03:18

    Make the median of your data (or more precisely, the nearest element in your array to the median) the root of the tree. And so on recursively.

提交回复
热议问题