字符串的有序二叉树 [英] Ordered Binary Tree of Strings
问题描述
这些值输入到有序的二叉树中:Mercury
,Venus
,Earth
,Mars
,Jupiter
,Saturn
和Uranus
.
These values are entered into an ordered binary tree: Mercury
, Venus
, Earth
, Mars
, Jupiter
, Saturn
and Uranus
.
生成的二叉树应该就是这个.
The resulting binary tree is supposed to be this.
Mercury
/ \
Earth Venus
\ /
Jupiter Saturn
\ \
Mars Uranus
此订单是否有任何原因?木星不应该在金星分支下吗?
Is there any reason for this order? Shouldn't Jupiter be under the Venus branch?
推荐答案
有序二叉树"是指二叉搜索树.只要树满足以下条件:
By "ordered binary tree", I assume you mean a binary search tree. As long as the tree satisfies the following criteria:
1. The key in a node is greater than (or equal to) any key stored in its left subtree.
2. The key in a node is less than (or equal to) any key stored in its right subtree.
然后,树的确切结构取决于添加键的顺序以及用于构造树的确切算法.
then the exact structure of the tree depends on the order in which the keys are added and the exact algorithm used to construct the tree.
但是,您表示您相信木星应该出现在金星的子树中.您的订购标准是什么?如果按字母顺序对名称进行比较,则显示的树是有效的.
However, you indicate that you believe that Jupiter should occur in the subtree of Venus. What is your ordering criteria? The tree you show is valid if the names are being compared alphabetically.
这篇关于字符串的有序二叉树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!