如何描述和编码算法以检查两个二进制树是否相同?
他们的质量标准要求我使用适当的语法并写下我已经尝试过的内容,但我确实没有信息。它只是要求我这样做,我不知道如何开始。
相同的
binary tree please help
Their quality standards require me to use proper grammar and write what I have already tried but I have really no information. It just asks me to do that and I have no idea how to start.
identical
binary tree please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要检查两棵树是否相同,则可以简单地同时穿越两棵树。在穿越两棵树时,如果一个节点存在于一棵树上,而在另一棵树上不存在,则树是不相同的。
您可以采用此处描述的递归方法: https://www.geeksforgeeks.org/write-c-code-to-determine-if-two-trees-rees-are-sideical/
现在,如果您想检查两个树是否是 iNSOMORPHIC ,您可以做到多种方法。为了高准确性和良好的性能,您可能正在寻找一种用两种树木放置的方式。
If you want to check if two trees are identical, you can simply simultaneously traverse the two trees. When traversing the two trees, if a node exists on one tree but not on the other, then the trees are not identical.
You can take the recursive approach described here: https://www.geeksforgeeks.org/write-c-code-to-determine-if-two-trees-are-identical/
Now if you want to check if two trees are isomorphic, there are a range of ways you could do that. For high accuracy and good performance you would probably be looking for some way to hash both the trees.