我们什么时候可以使用简单二叉树而不是二叉搜索树?
When can we use Simple Binary Tree over Binary Search Tree?
很多教程都侧重于二叉搜索树的实现,搜索操作更简单。是否存在实施简单二叉树优于 BST 的应用程序或情况?还是只是作为树木的入门概念来教授?
当您的结构需要一个 parent 和最多两个 children 时,您可以使用二叉树(而不是二叉搜索树)。例如,考虑用一棵树来表示数学表达式。表达式 (a+b)*c
变为:
*
/ \
+ c
/ \
a b
Paring heap is a data structure that is logically a general tree (i.e. no restriction on the number of children a node can have), but it is often implemented using a left-child right-sibling binary tree。 LCRS 二叉树通常比一般树更有效且更易于使用。
binary heap也是二叉树,但不是二叉搜索树。
玩家回答一堆 yes/no 问题以获得答案的旧猜谜游戏是二叉树的另一个示例。在下面的树中,左边 child 是 "No" 答案,右边 child 是 "Yes" 答案
Is it an animal?
/ \
Is it a plant? Is is a mammal?
/ \
A reptile? A dog?
你可以想象一棵任意深的树,每一层都有问题。
这些只是几个例子。我发现二叉树在很多不同的情况下都很有用。
很多教程都侧重于二叉搜索树的实现,搜索操作更简单。是否存在实施简单二叉树优于 BST 的应用程序或情况?还是只是作为树木的入门概念来教授?
当您的结构需要一个 parent 和最多两个 children 时,您可以使用二叉树(而不是二叉搜索树)。例如,考虑用一棵树来表示数学表达式。表达式 (a+b)*c
变为:
*
/ \
+ c
/ \
a b
Paring heap is a data structure that is logically a general tree (i.e. no restriction on the number of children a node can have), but it is often implemented using a left-child right-sibling binary tree。 LCRS 二叉树通常比一般树更有效且更易于使用。
binary heap也是二叉树,但不是二叉搜索树。
玩家回答一堆 yes/no 问题以获得答案的旧猜谜游戏是二叉树的另一个示例。在下面的树中,左边 child 是 "No" 答案,右边 child 是 "Yes" 答案
Is it an animal?
/ \
Is it a plant? Is is a mammal?
/ \
A reptile? A dog?
你可以想象一棵任意深的树,每一层都有问题。
这些只是几个例子。我发现二叉树在很多不同的情况下都很有用。