简体   繁体   English

两个不同形状的BST的Will数组形式始终具有不相等的数组

[英]Will array form of two different shape BSTs always have non-equal arrays

Is it correct that two BSTs that differs in shape (value may differ) have different arrays versions having either, 形状不同(值可能不同)的两个BST是否具有不同的数组版本(包括其中之一)是否正确,

a) Different array length. a)不同的数组长度。

b) If length is same then indexes on which values exist differ. b)如果长度相同,则存在值的索引会不同。 (assume if A[i]==0 means empty or null child of tree) (假设A[i]==0表示树的子级为空或为空)

I am creating logic to tell if two trees have same shape or not without using recursion. 我正在创建逻辑来告诉两棵树是否具有相同的形状而无需使用递归。 I first convert trees to arrays and then compare there arrays. 我首先将树转换为数组,然后比较那里的数组。 I am writing this for an online practice challenge question. 我正在为在线练习挑战性问题撰写本文。 When I put there given sample trees and some of my own sample trees I get correct results. 当我把给定的样本树和一些自己的样本树放到那里时,我得到正确的结果。 But when I submit it it says wrong answer. 但是,当我提交时,它说错了答案。 So I was thinking maybe this may not hold true for large trees. 所以我在想,也许这可能不适用于大树。

Kindly, tell me If I am looking at things wrong. 如果我看错了,请告诉我。

-Thanks -谢谢

It Depends If both of BST have same number of Nodes the Array Should be of Size of Full Tree(to avoid any possible errors). 这取决于两个BST是否具有相同数量的节点,该阵列的大小应为全树大小(以避免任何可能的错误)。 So Array Size Should not be used to determine the shape of given tree. 因此,不应将数组大小用于确定给定树的形状。 Secondly For the tree have same shape (as you wish to guess). 其次,因为树具有相同的形状(如您所想)。 The Corresponding Array Indices should be filled, or you can say that both arrays should be equivalent( may be not equal in values). 应该填写相应的数组索引,或者可以说两个数组应该相等(值可能不相等)。 If these both conditions are verified then both can create same shape. 如果这两个条件都得到验证,那么两者都可以创建相同的形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM