It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
给定两棵树,你如何发现其中一棵树是另一棵树的子树?
为此给出最佳算法…并给出你所回答的顺序…
最佳答案
首先想到的是穿过一棵树,看看它的孩子是否是另一棵树的头然后倒过来。
如果你知道每棵树的高度,你可能就能知道哪棵树可能是另一棵树的子树。
如果您知道树的其他细节或特征(排序或不排序、平衡或不平衡),您可以使用这些特征提出更快的算法。
10-06 09:45