Determine if a binary tree is subtree of another binary tree using pre-order and in-order strings

前端 未结 6 934
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 05:44

I want to find out whether binary tree T2 is a subtree of of binary tree T1. I read that one could build string representations for T2 and T1 using pre-order and in-

6条回答
  •  情深已故
    2020-12-09 06:15

    The definition of sub-tree of a tree should be same as the definition of sub-string of a string. Think of it like this: 1. sub-string has begins-with, contains and ends-with. 2. Tree should also have the same definition but generalized to suit the Tree data structure. 3. The generalization is from 1 dimensional for string to 2 dimensional for tree.

提交回复
热议问题