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

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Advanced Topics in Algorithms and Data Structures
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/L2-GraphsAndTrees.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Dynamic Planar Convex Hull Operations in Near- Logarithmic Amortized Time TIMOTHY M. CHAN.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
GOLOMB RULERS AND GRACEFUL GRAPHS
Data Structures and Algorithms1 Trees The definitions for this presentation are from from: Corman, et. al., Introduction to Algorithms (MIT Press), Chapter.
CS 171: Introduction to Computer Science II
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Discussion #36 Spanning Trees
1 Trees. 2 Outline –Tree Structures –Tree Node Level and Path Length –Binary Tree Definition –Binary Tree Nodes –Binary Search Trees.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
CSC 2300 Data Structures & Algorithms February 6, 2007 Chapter 4. Trees.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Trees.
Binary Trees Chapter 6.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
COSC2007 Data Structures II
Advanced Algorithms Analysis and Design Lecture 8 (Continue Lecture 7…..) Elementry Data Structures By Engr Huma Ayub Vine.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
CS Data Structures Chapter 5 Trees. Chapter 5 Trees: Outline  Introduction  Representation Of Trees  Binary Trees  Binary Tree Traversals 
Lecture 81 Data Structures, Algorithms & Complexity Tree Algorithms GRIFFITH COLLEGE DUBLIN.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
CSIT 402 Data Structures II
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
1 Chapter 10 Trees. 2 Definition of Tree A tree is a set of linked nodes, such that there is one and only one path from a unique node (called the root.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 4. Trees.
Prepared by- Jatinder Paul, Shraddha Rumade
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Discrete Structures Trees (Ch. 11)
Introduction to Graph Theory
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Discrete Mathematics Chapter 5 Trees.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
CMSC 341 Introduction to Trees. 2/21/20062 Tree ADT Tree definition –A tree is a set of nodes which may be empty –If not empty, then there is a distinguished.
DATA STRUCTURE BS(IT)3rd. Tree An Introduction By Yasir Mustafa Roll No. BS(IT) Bahauddin Zakariya University, Multan.
1 Binary Search Trees  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
1 Trees. 2 Trees Trees. Binary Trees Tree Traversal.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Trees Chapter 15.
CSCE 210 Data Structures and Algorithms
Chapter 5 : Trees.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Binary Trees, Binary Search Trees
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
CS223 Advanced Data Structures and Algorithms
Graph Algorithms Using Depth First Search
Trees 1: Theory, Models, Generic Heap Algorithms, Priority Queues
Binary Trees, Binary Search Trees
Trees.
Binary Trees, Binary Search Trees
Presentation transcript:

“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 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 to any 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.

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

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

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

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 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 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 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 Isomorphic trees Observation: free trees are isomorphic iff the rooted trees assigned to them are isomorphic.

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

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 …..….. …. A B C D

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

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

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

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

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

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

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 Canonical Index (example)

25 Checking isomorphism of two given trees u k v k

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

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

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

Example

h = 0

Example h = 1

Example h = 2

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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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}

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) {u1,u3}{u2} {u4} Dh Dh  =3  =4  =5  =  max +1

Example

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

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.

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

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.

Questions…?