【发布时间】:2015-06-29 08:19:18
【问题描述】:
此问题已在此处提出:http://stackoverflow.com/questions/14092710/equality-of-two-binary-search-trees-constructed-from-unordered-arrays。
但是,我想到的解决方案相当简单,但那里没有提到。
问题陈述为:Given two arrays which represent a sequence of keys. Imagine we make a Binary Search Tree (BST) from each array. We need to tell whether two BSTs will be identical or not without actually constructing the tree.
我想到的是,只需对两个数组进行排序。如果它们相同,那么它们的中序遍历也将相同,因此如果两个数组相同,那么它们肯定会导致相同的 BST。我假设如果两个二叉搜索树的中序遍历相同,那么树也相同,我错了吗?
【问题讨论】: