1 / 56

“On an Algorithm of Zemlyachenko for Subtree Isomorphism”

“On an Algorithm of Zemlyachenko for Subtree Isomorphism”. Yefim Dinitz, Alon Itai, Michael Rodeh (1998) Presented by: Masha Igra, Merav Bukra. Agenda. Introduction Definition of Canonical Order Overview of the Algorithm Time Complexity Hopcroft and Tarjan’s Canonical Order. Agenda.

tavi
Download Presentation

“On an Algorithm of Zemlyachenko for Subtree Isomorphism”

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. 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. Reduction to rooted case • A vertex is central if its greatest distance from it toany other vertex is as small as possible.

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

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

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

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

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

  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. 11

  12. Isomorphic graphs Graphs G1= {V1, E1} and G2 = {V2, E2}are isomorphic if: 1. There is a bijection f from V1 to V2 and 2. There is a bijection g from E1 to E2 that maps each edge (v, u) to (f(v), f(u)). G H

  13. 7 7 4 4 5 5 6 6 1 1 2 2 3 3 Isomorphic trees • An ordered tree is a rooted tree in which the children of each node are ordered. 7 • Isomorphic rooted trees: ordered trees that differ only in the order of siblings. 4 5 6 1 2 3 • Observation: free trees are isomorphic iff the rooted trees assigned to themare isomorphic. 13

  14. 6 3 7 2 1 5 4 Isomorphism equivalence class 6 6 ….. 2 7 3 7 2 3 4 5 1 1 4 5 • In any isomorphism equivalence class of rooted trees, a particular canonically ordered tree will bedefined. • 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.

  15. Isomorphism equivalence class 6 3 7 2 1 5 4 A C 6 …. …. ….. 2 7 3 4 5 1 B D …. …. • Two trees in the same isomorphism equivalence class have the same canonical representation. • There are many kinds ofcanonical representations, we are going to describe one of them. 15

  16. 6 3 7 2 1 5 4 Preorder traversal • Preorder traversal: • Visit root. • Traverse children from left to right recursively. 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. Subree isomorphism T r Tu • Let Tv, the subtree rootedatv, be the subtree that contains v. • u and v are subtree isomorphic when Tu and Tv are isomorphic. u Tv v • 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

  19. 1 1 4 9 1 2 Canonical Order of vertices • The canonical order on verticesis defined from the leaves up. The leaves are the minimal elements of . • To determine whetheruv : • Compare their heights: • if height(u) < height(v), thenu v • if height(u) == height(v), • then sort the children of u and v to create two lists: • u1 u2 …. ud(u) • v1 v2 …. vd(v) • uvif and only if the sorted list ofu’s children is lexicographically less than the sorted list ofv’schildren.

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

  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. 1 1 1 1 1 1 1

  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: • vzuw • = = 2 • = 3 • = 4 z u v w 2 3 2 4 1 1 1 1 1 1 1 22

  23. Canonical Index u v 2 2 3 3 3 3 9 9 • 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. 23

  24. Canonical Index (example) 5 4 4 2 2 3 2 3 1 1 1 1 1 1 1

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

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

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

  28. Data structuresof the Algorithm • Array level[h] = all the vertices of height h. • Arraychildren[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 treeDh

  29. Example

  30. Example h = 0

  31. Example h = 1

  32. Example h = 2

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

  34. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 Dh. • Then we move u down to the child d’ of d whose label is . [v] D h = 2 root {u1, u2, u3, u4}

  35. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u1, u2, u3, u4} d u v

  36. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u2, u3, u4} d u 1 {u1} d’ v

  37. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 u root {u2, u3, u4} d 1 v {u1}

  38. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 u root {u2, u4} d 1 v {u1, u3} d’

  39. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u2, u4} u 1 {u1, u3} d v

  40. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u2, u4} u 1 {u3} d v d’ 2 {u1}

  41. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u2, u4} d u 1 {u3} v 2 {u1}

  42. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u4} d u 1 2 {u3} {u2} v 2 {u1}

  43. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u4} u 1 2 {u3} d {u2} v 2 {u1}

  44. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root {u4} u 1 2 {u3} d {} v d’ 2 2 {u1} {u2}

  45. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root u {u4} 1 2 v {u3} d {} 2 2 {u1} {u2}

  46. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root u {u4} 1 2 v {} d {} d’ 2 2 {u1, u3} {u2}

  47. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root u {u4} d 1 v 2 {} {} 2 2 {u1, u3} {u2}

  48. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root u {} d 1 v 2 {} d’ {u4} 2 2 {u1, u3} {u2}

  49. Auxiliary ordered treeDh • Dh construction: • Single vertex – root, to which all vertices of level[h] are associated. • 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 . [v] D h = 2 root 1 2 {u4} 2 2 {u1, u3} {u2}

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

More Related