由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - EPI 题目
相关主题
这个Binary Tree的题来看看amazon on-site interview
如何判断一个tree是另外一个tree的subtree?插入节点到complete binary tree的末尾
微软面试的一道题serialize tree可否用in order或者post order
贴一道老算法题serialize n-ary tree 一问
问个G家店面题完全二叉树问道题
判断一个树是不是另一个树的子树?Amazon phone interview Software Engineering Intern
[Algo] 检查一个树是另一个的子树fb面经的一题
Uni_value subtree problem两个有点难度很有意思的题
相关话题的讨论汇总
话题: complete话题: tree话题: perfect话题: else话题: largest
进入JobHunting版参与讨论
1 (共1页)
m*******4
发帖数: 34
1
Write a function that returns the size of the largest subtree that is
complete.
请问怎么解啊
b*****a
发帖数: 70
2
I think you can always mail the authors about the questions you had.
T******e
发帖数: 157
3
可不可以这样,对于每个节点,NULL就返回0,如果其左子树和右子树返回的数目相等
,就说明到这个节点为止的树是满的(但这并不说明这个节点以下所有树都是满的,只
说明起码该节点加上其左右子树是满树),就返回左子树+右子树+1,否则就返回1,代
表自己的节点。
然后每次recursive都带一个引用的max存全局的最大值
w*******s
发帖数: 138
4
EPI的题书上不是有答案吗

【在 T******e 的大作中提到】
: 可不可以这样,对于每个节点,NULL就返回0,如果其左子树和右子树返回的数目相等
: ,就说明到这个节点为止的树是满的(但这并不说明这个节点以下所有树都是满的,只
: 说明起码该节点加上其左右子树是满树),就返回左子树+右子树+1,否则就返回1,代
: 表自己的节点。
: 然后每次recursive都带一个引用的max存全局的最大值

w*****t
发帖数: 485
5
similar with this:
http://leetcode.com/2010/11/largest-binary-search-tree-bst-in.h

【在 m*******4 的大作中提到】
: Write a function that returns the size of the largest subtree that is
: complete.
: 请问怎么解啊

m*******4
发帖数: 34
6

This is an extension problem. No answer

【在 w*******s 的大作中提到】
: EPI的题书上不是有答案吗
b*****a
发帖数: 70
7
I think your idea is correct with a tiny bug; what your algorithm is
returning the largest perfect binary tree instead of the largest complete
binary tree. With your algorithm, this problem can be solved in O(n) time I
think.

【在 T******e 的大作中提到】
: 可不可以这样,对于每个节点,NULL就返回0,如果其左子树和右子树返回的数目相等
: ,就说明到这个节点为止的树是满的(但这并不说明这个节点以下所有树都是满的,只
: 说明起码该节点加上其左右子树是满树),就返回左子树+右子树+1,否则就返回1,代
: 表自己的节点。
: 然后每次recursive都带一个引用的max存全局的最大值

b***e
发帖数: 1419
8
Assume we know the height of each node, which can be computed on the fly
with O(n). Then it's just an extensive case study on the 3 possible status
of a subroot: incomplete, complete (but not perfect), perfect.
if (!tree.left is not complete) {
tree is not complete
} else {
if (tree.left is not perfect) {
tree is not complete
} else {
if (tree.right is not complete) {
tree is not complete
} else {
if (tree.right is not perfect) {
if (tree.left.height == tree.right.height) {
tree is complete but not perfect
} else {
tree is not complete
}
} else {
if (tree.left.height == tree.right.height) {
tree is perfect
} else {
tree is not complete
}
}
}
}
}

【在 m*******4 的大作中提到】
: Write a function that returns the size of the largest subtree that is
: complete.
: 请问怎么解啊

l******6
发帖数: 340
9

status
if (tree.left is not perfect) {
The tree can be complete if tree.left is not perfect
that is tree.left is complete tree.right is perfect tree.left.height - tree
.right.height = 1

【在 b***e 的大作中提到】
: Assume we know the height of each node, which can be computed on the fly
: with O(n). Then it's just an extensive case study on the 3 possible status
: of a subroot: incomplete, complete (but not perfect), perfect.
: if (!tree.left is not complete) {
: tree is not complete
: } else {
: if (tree.left is not perfect) {
: tree is not complete
: } else {
: if (tree.right is not complete) {

b***e
发帖数: 1419
10
That's right, made up. Thanks.

tree

【在 l******6 的大作中提到】
:
: status
: if (tree.left is not perfect) {
: The tree can be complete if tree.left is not perfect
: that is tree.left is complete tree.right is perfect tree.left.height - tree
: .right.height = 1

1 (共1页)
进入JobHunting版参与讨论
相关主题
两个有点难度很有意思的题问个G家店面题完全二叉树
求教balanced binary tree的准确定义判断一个树是不是另一个树的子树?
有人了解并行算法么[Algo] 检查一个树是另一个的子树
分享一道面试题Uni_value subtree problem
这个Binary Tree的题来看看amazon on-site interview
如何判断一个tree是另外一个tree的subtree?插入节点到complete binary tree的末尾
微软面试的一道题serialize tree可否用in order或者post order
贴一道老算法题serialize n-ary tree 一问
相关话题的讨论汇总
话题: complete话题: tree话题: perfect话题: else话题: largest