相关疑难解决方法(0)

从已排序的链接列表创建平衡二进制搜索树

从排序的单链表创建平衡二叉搜索树的最佳方法是什么?

algorithm tree linked-list

20
推荐指数
1
解决办法
3万
查看次数

构建平衡的二叉搜索树

有没有一种方法来构建平衡的二叉搜索树?

例:

1 2 3 4 5 6 7 8 9

       5
      / \
     3   etc
    / \
   2   4
  /
 1
Run Code Online (Sandbox Code Playgroud)

我想有一种方法可以做到这一点,而不使用更复杂的自平衡树.否则我可以自己做,但有人可能已经这样做了:)


谢谢你的回答!这是最后的python代码:

def _buildTree(self, keys):
    if not keys:
        return None

    middle = len(keys) // 2

    return Node(
        key=keys[middle],
        left=self._buildTree(keys[:middle]),
        right=self._buildTree(keys[middle + 1:])
        )
Run Code Online (Sandbox Code Playgroud)

c# python binary-tree

10
推荐指数
2
解决办法
9970
查看次数

标签 统计

algorithm ×1

binary-tree ×1

c# ×1

linked-list ×1

python ×1

tree ×1