Download presentation
Presentation is loading. Please wait.
1
Tree isomorphism Bogdan Kalashnikov FI-2 kalashnikovbv@ukma.edu.ua
2
What is a tree A tree is a perennial woody plant... :-)
3
What is a tree...or a tree is a commonly used structure of data that has a hierarchical tree structure with a set of linked nodes.
4
Tree as a graph The tree can also be regarded as a graph, where each node can have zero or more children nodes and no more than one parent node.
5
The node, which has no parent is called a root node. The nodes, which have both parents and children nodes are called the internal nodes. The nodes, which have no son nodes are called the leaf nodes.
6
Isomorphism of trees Actually, we say that two trees are isomorphic if one can be transformed into the other simply by renaming nodes. Or two trees are isomorphic if one can be get from the other just by swapping the son nodes of the one parental node.
7
The example of isomorphic trees
8
The algorithm To find out if two rooted unordered trees with n nodes are isomorphic we will use the following algorithm, which will solve the problem in O(n) time.
9
The algorithm This algorithm assigns integers to all the nodes of the two trees, starting with the leaves and working up towards the roots. This way, the two trees are isomorphic if and only if their roots are assigned the same integer.
10
Step 1 assign level numbers to all nodes of T1 and T2 assign to all leaves of T1 and T2 the integer 0
11
Step 2 let L1 be a list of the leaves of T1 at level 0 let L2 be a list of the leaves of T2 at level 0 L1 = => L2 = => As we can see the trees T1 and T2 are isomorphic on this level.
12
Step 3 for all levels starting from 1 do assign integers to all nodes at level i
13
Step 4 if the roots of T1 and T2 are assigned the same numbers then T1 and T2 are isomorphic else T1 and T2 are not isomorphic end algorithm
14
Results Consequently, since the roots a and n are asigned the same numbers, the trees T1 and T2 are isomorphic.
15
The usage of this algorithm The algorithm allows us to solve several tree comparison problems in linear time, such as subtree isomorphism, largest common subtree and the most often repeated subtree.
16
Subtree isomorphism Find all the subtrees in a given forest which are isomorphic to the subtree rooted at a given node
17
Largest common subtree Find all the largest common subtrees in a given forest. More in general, find all the k-th largest or the k-th smallest common subtrees in the given forest.
18
Most often repeated subtree Find all the subtrees in a given forest that are repeated most often. More in general, find in the given forest all the k-th most often or the k- th least often repeated subtrees
19
Sources 1. A. V. Aho, J. E. Hopcroft, and J. D. Ullman. The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974. 2. М. М. Глибовець. Основи Комп’ютерних Алгоритмів. КМ Академія, 2003.
20
Thank you for attention!!! Kalashnikov Bogdan FI-2 kalashnikovbv@ukma.edu.ua
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.