Balanced Binary Search Tree

后端 未结 2 1133
情书的邮戳
情书的邮戳 2021-01-17 01:54

I need to build a balanced binary search tree. So far my program inserts the numbers from 1 to 26, but my program does not build it into a balanced binary search tree. If an

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 02:29

    Since your tree does not self-balance, whether or not it's balanced will depend on the order of insertion of the elements.

    If you want your tree to be balanced regardless, you will need to take care of the balancing in your class. For example, take a look at the Red-Black Tree data structure.

提交回复
热议问题