avatar
J*3
2
把BT->double LL
然后找Intersect 点?
avatar
z*g
3
not sure whether I'm correct or not.
serialize the b-trees with null mark.
Then, find longest common substring.
recheck if they r not isomorphic.
avatar
f*d
4
好主意~
不过感觉不正确, 不同的结构都可能出来一模一样的serialization result~

【在 z******g 的大作中提到】
: not sure whether I'm correct or not.
: serialize the b-trees with null mark.
: Then, find longest common substring.
: recheck if they r not isomorphic.

avatar
f*d
5
感觉不正确, 理由还是,不同的结构都可能出来一模一样的double LL

【在 J****3 的大作中提到】
: 把BT->double LL
: 然后找Intersect 点?

avatar
g*9
6
Re,坐等大侠解答~~
avatar
s*e
7
Given two BTs T1 and T2, return the larest common subtree
idea:
step one:
首先分别对T1, T2做预处理,求出每个subtree的nodes总个数,把得到的结果存到
hashtable里面,这一步时间复杂度O(N), N=number of nodes
step two:
从root开始从上到下对每对相对应的node pair,判断以他们为root的subtree是否相同
given node1 from t1, node2 from t2
f(node1,node2)= true if node1 == node2 && f(node1.left, node2.left) && f(
node1.right, node2.right)
这个过程可以使用dp的思想,建个hashtable存放f的值,key=node1.hashcode+"-"+
node2.hashcode, value=boolean
这一步时间复杂度O(N)
step three:
有了第一步的每个subtree 的size, 第二步的每对subtree是否相同,这一步只需要从
root开始找那个最大size的common subtree就可以了
貌似整个算法时间复杂度就是O(N)
大神们看看这个思路work不?
avatar
c*1
8
define what do you mean by "equal". especially, are they equal:
root=1, root->left=2
root=1, root->right=2
avatar
r*c
9
上面有人提到isomorphic

【在 c**1 的大作中提到】
: define what do you mean by "equal". especially, are they equal:
: root=1, root->left=2
: root=1, root->right=2

avatar
k*j
10
加了NULL之后应该没有这个问题,SERIALIZE之后一定是唯一的

【在 f*********d 的大作中提到】
: 好主意~
: 不过感觉不正确, 不同的结构都可能出来一模一样的serialization result~

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。