Presentation is loading. Please wait.

Presentation is loading. Please wait.

“On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra.

Similar presentations


Presentation on theme: "“On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra."— Presentation transcript:

1 “On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra

2 Agenda Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

3 Agenda Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

4 4 Introduction A free tree is a connected, acyclic and undirected graph Free Tree A rooted tree is a free tree in which one of vertices is distinguished from others as its root. Rooted Tree

5 5 Reduction to rooted case A vertex is central if its greatest distance from it to any other vertex is as small as possible.

6 6 Reduction to rooted case A vertex is central if its greatest distance from any other vertex is as small as possible.

7 7 Reduction to rooted case A vertex is central if its greatest distance from any other vertex is as small as possible.

8 8 Reduction to rooted case A vertex is central if its greatest distance from any other vertex is as small as possible.

9 9 Reduction to rooted case A vertex is central if its greatest distance from any other vertex is as small as possible.

10 10 Reduction to rooted case In case of the central edge, a new vertex will be connected to the endpoints of the central edge.

11 11 Reduction to rooted case In case of the central edge, a new vertex will be connected to the endpoints of the central edge. Thus, we assign to any free tree a unique rooted tree.

12 12 Graphs G 1 = {V 1, E 1 } and G 2 = {V 2, E 2 } are isomorphic if: 1. There is a bijection f from V 1 to V 2 and 2. There is a bijection g from E 1 to E 2 that maps each edge (v, u) to (f(v), f(u)). Isomorphic graphs GH

13 13 An ordered tree is a rooted tree in which the children of each node are ordered. Isomorphic rooted trees: ordered trees that differ only in the order of siblings. 6 7 45 132 4 7 65 321 6 7 45 132 Isomorphic trees Observation: free trees are isomorphic iff the rooted trees assigned to them are isomorphic.

14 14 Isomorphism equivalence class In any isomorphism equivalence class of rooted trees, a particular canonically ordered tree will be defined. For any tree T, let us call such a distinguished tree in the isomorphism class of T the canonical representation of T. Two rooted trees are isomorphic if and only if their canonical representations coincide. 2 6 37 145 2 6 37 154 2 6 37 154 …..

15 15 Isomorphism equivalence class Two trees in the same isomorphism equivalence class have the same canonical representation. There are many kinds of canonical representations, we are going to describe one of them. 2 6 37 145 2 6 37 154 …..….. …. A B C D

16 16 Preorder traversal Preorder traversal: –Visit root. –Traverse children from left to right recursively. 2 6 37 145 Traversal sequence: { 6, 3, 7, 1, 2, 5, 4 }

17 Agenda Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

18 18 Subree isomorphism Let T v, the subtree rooted at v, be the subtree that contains v. u and v are subtree isomorphic when T u and T v are isomorphic. Height of a vertex v is the length of the path from v to the farthest leaf of its subtree. height( v ) = 2, height( r ) = 4 u r v T TvTv TuTu

19 19 To determine whether u v : 1.Compare their heights : if height( u ) < height( v ), then u v 2.if height( u ) == height( v ), then sort the children of u and v to create two lists: u 1 u 2 …. u d(u) v 1 v 2 …. v d(v) u v if and only if the sorted list of u ’ s children is lexicographically less than the sorted list of v ’ s children. Canonical Order of vertices The canonical order on vertices is defined from the leaves up. The leaves are the minimal elements of. 1 1 4 9 1 2

20 20 For example: Children of u : 1 2 Children of v : 1 2 => v u Thus u v if and only if height( u ) = height( v ), and d( u ) = d( v ) and u i v i for i = 1,..., d( u ). Canonical Order u v 1 1 1 1 2 2

21 21 Canonical Index of subtree isomorphism classes Starts with leaves (height 0): All leaves are isomorphic to each other, and have the minimum index 1. 1111111

22 22 Canonical Index of subtree isomorphism classes Starts with leaves (height 0): All leaves are isomorphic to each other, and have the minimum index 1. Height = 1: v z u w = = 2 = 3 = 4 w u z v 1111111 2324

23 23 Canonical Index Lemma: Two vertices have the same canonical index (label) iff they are isomorphic. By induction: Assumption: Correct for any height less than h. Step (height h): u and v are isomorphic by the assumption and the definition. u 2339 v 2339

24 24 Canonical Index (example) 1 11 1 11 32 1 2 2 3 4 4 5

25 25 Checking isomorphism of two given trees u k v k

26 26 For each height h : –Sort lists consisting of the children of vertices of height h. Total time will be We wish time O(n) Since the numbers to be sorted are in range 1…n, bucket-sort can ensure O(n i +range) for each sort. In worst case: where the ranges of indexes and heights are of order n, algorithm requires. Straightforward implementation 1 4 3 2 11 1 1 5 1 6 1 7

27 Agenda Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

28 28 Array level[h] = all the vertices of height h. Array children[h] = all the children of all vertices at level[h], sorted by their index. Construct the canonical indexes level by level: –level[0] – the leaves. –level[h] – assume that we already found the indexes of all vertices at lower levels: Construct new auxiliary data structure: ordered tree D h Data structures of the Algorithm

29 Example

30 h = 0

31 Example h = 1

32 Example h = 2

33 33 The process of construction of D h (example): 1.Single vertex – root, to which all vertices of level[h] are associated. Auxiliary ordered tree D h {u1, u2, u3, u4} root D h = 2

34 34 Auxiliary ordered tree D h {u1, u2, u3, u4} root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to vertex d of D h. Then we move u down to the child d’ of d whose label is. h = 2  [v]

35 35 Auxiliary ordered tree D h {u1, u2, u3, u4} root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[ h ] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d

36 36 Auxiliary ordered tree D h {u2, u3, u4} root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d d’ {u1} 1

37 37 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u2, u3, u4} {u1} 1

38 38 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u2, u4} {u1, u3} 1 d’

39 39 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u2, u4} {u1, u3} 1

40 40 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u2, u4} {u3} 1 2 d’ {u1}

41 41 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u2, u4} {u3} 1 2 {u1}

42 42 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {u3} 1 2 {u1} 2 {u2}

43 43 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {u3} 1 2 {u1} 2 {u2}

44 44 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {u3} 1 2 {u1} 2 2 {u2} {} d’

45 45 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {u3} 1 2 {u1} 2 2 {u2} {}

46 46 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {} 1 2 {u1, u3} 2 2 {u2} {} d’

47 47 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {u4} {} 1 2 {u1, u3} 2 2 {u2} {}

48 48 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] u v d {} 1 2 {u1, u3} 2 2 {u2} {u4} d’

49 49 Auxiliary ordered tree D h root D D h construction: 1.Single vertex – root, to which all vertices of level[h] are associated. 2.Scan the array children[h] of level[ h] by non decreasing order: Suppose v is a child of u, and u was associated to d. Then we move u down to the child d’ of d whose label is. h = 2  [v] 1 2 {u1, u3} 2 2 {u2} {u4}

50 Traversing in preorder, on arrival to each new vertex of T – increasing the current canonical index by 1. Overview of the Algorithm (for height h) 2 22 1 {u1,u3}{u2} {u4} Dh Dh  =3  =4  =5  =  max +1

51 Example

52 Agenda Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

53 Time Complexity The Time Complexity of the whole algorithm is O(n). Since we traverse the nodes by heights, we handle each node only once. For each height, we construct Dh from children[h]. Each creation of d’ takes O(1), since we do not need search of its place in Dh: We always add the rightmost leaf of Dh. The number of vertices of Dh for all h=0,…,height(T) is O(n). We don’t need to sort Dh because of the efficient insertions. Traversing Dh is linear in the number of vertices.

54 Agenda Introduction Definition of Canonical Order Overview of the techniques of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order

55 Their work is aimed at tree isomorphism only, rather than isomorphism together with subtree isomorphism. They based on the depth (the distance from the root), which also distinguishes between vertices. Index(u) = Index(v) iff depth(u) = depth(v) and T u and T v are isomorphic. Since the indexes are given in increasing order, the indexes of all the vertices of any fixed depth d form a set of consecutive integers. All children of depth d are at the depth d+1. Thus, the sets of children in distinct phases are disjoint. Therefore, the sum of their sizes is at most n. (Using bucket-sort may be done in time O(n), not Omega(n^2), as at our height-based approach.) The lack of their algorithm: Given the subtree isomorphism classes, it is easy to construct their classes. We do not know how to perform the reverse direction.

56 Questions…?


Download ppt "“On an Algorithm of Zemlyachenko for Subtree Isomorphism” Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra."

Similar presentations


Ads by Google