What does it mean for two binary trees to be isomorphic?

拜拜、爱过 提交于 2019-11-30 03:16:35

Isomorphic comes from the Greek "same shape" (like isobar is points with the same air pressure and polygon means "many sided") so your understanding is correct. But don't make the mistake of assuming shape in this case is a physical shape (like the tree has one root, one left node and one right node; see below for example). Mathematicians have their own language which only sometimes bears a passing relationship to English :-)

It's not just binary trees. In mathematics, two structures are isomorphic if their properties are preserved regardless of their expression (you can have a function that translates A to B and another from B to A without loss of information).

For your particular case, it's the information in the tree that's preserved. For example, if that information is the sorted elements {1,2,3}, then the tree doesn't have to be the same physical shape at all - the following two would be isomorphic:

  2      1
 / \      \
1   3      2
            \
             3

A sorted linked list (or sorted array, for that matter) is also isomorphic to those since, in that case, no information would be lost in the transformations between the two.

If the binary tree was used in a manner where sort order was irrelevant (i.e., a "bag" sort of container), then the information would just be the contents in any order, and all the following would be isomorphic (that second last one's just a bag, the last is a list):

  2      1           2   3                   +---+  +---+  +---+
 / \      \         /     \      +-------+   | 3 |->| 1 |->| 2 |
1   3      2       1       2     | 1,3,2 |   +---+  +---+  +---+
            \     /         \    +-------+
             3   3           1

Of course, an unsorted tree may be considered to be a bit of a waste depending on your needs, but that's not relevant to this particular discussion.

Following conditions must fulfill to two trees to be isomorphic :
1. Two Tree are isomorphic if and only if they preserve same no of levels and same no of vertices in each level .

2.Two trees are isomorphic if and only if they have same degree spectrum .

3.Two trees are isomorphic if and only if they have same degree of spectrum at each level.

  1. Total no of leaf descendant of a vertex and the level number of vertex are both tree tree isomorphic invariant .

IN Simple words :
Two trees are isomorphic if one tree can be obtained from other by performing any number of flips i.e swapping left childrens and right childrens of a number of node .

Example of isomorphic trees:

Ref: 1.http://www14.in.tum.de/konferenzen/Jass03/presentations/eterevsky.pdf 2.http://www.geeksforgeeks.org/tree-isomorphism-problem/

I think your understanding is pretty much correct. If you ignore the values and just look at the structure, then for every node in the first tree there must be a corresponding node in the other tree and vice versa.

Naturally, both trees would have the same number of nodes. In addition, you could write a (super-naive) algorithm to confirm this isomorphism by attempting all possible mapping functions, and ensuring that for every node in the first tree that gets mapped to a node in the other, the corresponding mapping happens with the parent and with the two children. There are obviously efficient algorithms to check for this.

You may benefit from reading about graph isomorphism first; trees are a special (and easier to solve) case since they do not have cycles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!