填充二叉树使其成为 bst 的方法数
给定一组 n 个不同元素和一个具有 n 个节点的未标记二叉树。我们可以用给定的集合填充多少个树,使其成为二叉搜索树?
We are given a set of n distinct elements and an unlabeled binary tree with n nodes.In how many can we populate the tree with given set so that it becomes a binary search tree?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当为程序(任何语言)给出“树”时,这意味着将提供根节点地址以供遍历。
因此,根据我的说法,既然提供了“根节点”,就意味着树结构已经构建并固定为一种类型。
所以我认为只有一种可能的方法
when a "tree" would be given for a program(in any language) - it means the root node address will be provided for traversal.
Hence according to me since the "Root Node" is provided means the tree structure is already build and fixed into one type.
so i think there can be only one possible way
如果未标记意味着没有指定的根节点,则令
G = {G[1]..G[n]}
为以顶点1 为根的原始未标记树的图集... n
分别。然后,对于每个图
G[i]
,只有一种方法来填充树(为什么?——考虑树的根中必须有什么值,然后递归下降)。一旦你能证明这一点,答案一定是
k
,即集合G
中互非同构图的数量If by unlabeled you mean there's no specified root node, let
G = {G[1]..G[n]}
be the set of graphs of the original unlabeled tree rooted at vertices1 ... n
respectively.Then for each graph
G[i]
there is exactly one way to populate the tree (why? -- consider what value must be in the root of the tree, and descend recursively).Once you can show that, the answer must be
k
, the number of mutually nonisomorphic graphs in the setG