由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - A question about how to uniquely represent a binary tree
相关主题
问一道算法题Create Binary Tree from preorder and inorder arrays
F家phone interview的一道题reconstruct the tree from inorder and postorder lists
问几个有关Binary tree的题问个1337网页上面的经典题
LeetCode construct Binary Tree攒人品,amazon一面经历
Construct Binary Tree from Inorder and Postorder Traversalpreorder/postorder和inorder重建树有非递归的方法吗?
LeetCode题Binary Tree Inorder Traversal考大家个新题 visitor reconstruct generic tree
G家新鲜面经问一道二叉树遍历的问题? 谢谢!
贡献几道CS电面题现在怎么都是讨论offer的,没有做题的了?
相关话题的讨论汇总
话题: tree话题: binary话题: t2话题: t1话题: inordersa
进入JobHunting版参与讨论
1 (共1页)
c**y
发帖数: 172
1
I come up with some questions when considering the following problem. A
related discussion is found here
http://stackoverflow.com/questions/1017821/find-whether-a-tree- but I didn't find the answer to my particular questions.
Problem: given two binary trees T1 (large) and T2 (small), how do we check
whether or not T2 is a subtree of T1? Brutal force solution is out of scope
of this post. Another solution is as follows. A general idea is to serialize
T1 and T2 into two arrays A(T1) and A(T2) first, and then check if A(T2) is
a substring of A(T1). This solution is discussed here, http://www.geeksforgeeks.org/check-if-a-binary-tree-is-subtree-of-another-binary-tree/. According to Himanshu's post at above URL, we need to process these arrays slightly differently.
Following Himanshu's solution, we can serialize a binary tree with some
special processes: When serializing a binary tree in any order, use ‘(‘/‘
)’ to represent the left/right NULL children in the serialized array. We
use InOrderSA(T)/PreOrderSA(T)/PostOrderSA(T) to denote the specially
processed inorder/preorder/postorder arrays. For example, the special
inorder array of a tree T
2
/ \
1 3
is InOrderSA(T) = (1)2(3)
The special preorder array of a tree T'
2
\
3
is PreOrderSA(T') = 2((3)
Here are my questions
1. Does the array InOrderSA(T) alone determine a binary tree T WITHOUT
duplicate elements uniquely? If yes, do PreOrderSA(T) and PostOrderSA(T)
achieve the same thing?
2. Does the array InOrderSA(T) alone determine a binary tree T WITH
duplicate elements uniquely?
Your input is highly appreciated!
c**y
发帖数: 172
2
自己顶
l**b
发帖数: 457
3
这种题目,我可以说不能用json啊?会不会被直接藐视?
j********x
发帖数: 2330
4
跟json有什么关系?
j********x
发帖数: 2330
5
跟json有什么关系?
1 (共1页)
进入JobHunting版参与讨论
相关主题
现在怎么都是讨论offer的,没有做题的了?Construct Binary Tree from Inorder and Postorder Traversal
[leetcode] Binary Tree from Inorder & Postorder TraversalLeetCode题Binary Tree Inorder Traversal
Amazon 电面G家新鲜面经
讨论一道leetcode上面的题贡献几道CS电面题
问一道算法题Create Binary Tree from preorder and inorder arrays
F家phone interview的一道题reconstruct the tree from inorder and postorder lists
问几个有关Binary tree的题问个1337网页上面的经典题
LeetCode construct Binary Tree攒人品,amazon一面经历
相关话题的讨论汇总
话题: tree话题: binary话题: t2话题: t1话题: inordersa