现在的位置: 首页 > 综合 > 正文

ch4.7: given 2 huge Binary tree t1, t2(>1millon nodes), decide if one tree is subtree of another one

2014年07月07日 ⁄ 综合 ⁄ 共 303字 ⁄ 字号 评论关闭
implement the preetydraw snippets from leetcode for demonstration.

Executing the program....
$demo 

Balanced tree in array format
a1:
0----------6
3 1 0 2 5 4 6 Tree pretty print with level=1 and indentSpace=0


    ___3__
   /      \
  _1      _5
 /  \    /  \
 0   2   4   6
a2:
0----------2
1 0 2 Tree pretty print with level=1 and indentSpace=0


  _1
 /  \
 0   2

So we can easily verify that a2 is a subtree of a1.

抱歉!评论已关闭.