Subtree Isomorphism in O(n2.5) 丁文韬 丁基伟
Graph Matching Problems V1 V2 V3 V5 V4 V6 V7 H1 G H2 Graph isomorphism Bijection 𝜙: 𝑉 𝐺 → 𝑉 𝐻1 , 𝑢,𝑣 ∈ 𝐸 𝐺 iff. 𝜙 𝑢 ,𝜙 𝑣 ∈ 𝐸 𝐻1 Subgraph isomorphism 𝐺 is isomorphic to a 𝐻 𝑠 , which is a induced subgraph of 𝐻2 Graph monomorphism 𝐻 𝑠 is subgraph of 𝐻2 Graph homomorphism Two vertices in 𝐺 can be mapped to one vertex in 𝐻1.(𝜙 𝑉 1 𝐺 =𝜙 𝑉 3 𝐺 =𝑉 3 𝐻1 )
Subtree Isomorphism Determining if tree 𝑆 is isomorphic to any subtree of tree 𝑇. Find a mapping function from 𝑉 𝑆 to 𝑉(𝑇) Enumerate each vertex costs exponential time. Find a sub structure to decompose the problem S T
Decompose the Problem Decompose to vertices? A 5 1 2 3 4 6 7 8 D C B E D E 𝐴,𝐶 ∈𝑆 and 1,4 ∉𝑇
Decompose the Problem Limb 𝑙[𝑢,𝑣] denotes the maximal subtree containing (𝑢,𝑣) where 𝑣 is an end vertex of of it and is designated as the root of 𝑙 𝑢,𝑣 In a rooted tree 𝑇 𝑣 , 𝑙[𝑢,𝑣] is a limb of 𝑇[𝑣] if 𝑣 is farther than 𝑢 from root. 5 1 2 3 4 6 7 8 4 5 6 7 8 𝑙[4,5] in 𝑇
Limb 𝑙 𝑇 ≔ the set of limbs in 𝑇 Recursive Limited 𝑙 𝐷,𝐶 can be matched to 𝑇 unless 𝑙 𝐶,𝐴 , 𝑙 𝐶,𝐵 and 𝐷,𝐶 can be matched to 𝑇 Limited 𝑙 𝑇 =2 𝑛 𝑡 −1 𝑙 𝑇 𝑣 =( 𝑛 𝑡 −1) 𝑙(𝑇)= 𝑣∈𝑇 𝑙(𝑇[𝑣]) (Each edge corresponding to 2 limbs) D C A B 5 1 2 3 4 6 7 8
Matching Between Limbs Limb imbedding matrix R D C A B 5 1 2 3 4 6 7 8 E F 9 𝑙[5,4] 𝑙 5,6 𝑙 5,7 … (𝑅,𝐷) 1 𝑙[𝐷,𝐶] 𝑙[𝐷,𝐸] Lim imbedding submatrix of 𝑙 𝑅,𝐷 to 𝑙 9,5
Matching Between Limbs Convert to bipartite matching problem Bipartite matching problem can be solved within 𝑂( 𝑉 |𝐸|) time. Hopcraft-Karp algorithm 𝑙[𝐷,𝐶] 𝑙[𝐷,𝐸] 𝑙[5,4] 𝑙[5,6] 𝑙[5,7] 𝑅,𝐷 𝑙[5,4] 𝑙 5,6 𝑙 5,7 … (𝑅,𝐷) 1 𝑙[𝐷,𝐶] 𝑙[𝐷,𝐸]
Algorithm Select 𝑟∈𝑙𝑒𝑎𝑣𝑒𝑠 𝑆 as the root vertex, decompose 𝑆[𝑟] into limbs Set the limbs imbedding submatrix for leaves in 𝑆[𝑟] (All leaves can be matched to any limbs in 𝑇) For 𝑙 𝑢,𝑣 ∈𝑆 𝑟 in a topological order(e.g. ordered by non-decreasing height) For each 𝑙 𝑥,𝑦 ∈𝑇 Set the limbs imbedding submatrix by previous result. Build the corresponding bipartite graph Run H-K algorithm to determine whether 𝑙[𝑥,𝑦] contains 𝑙[𝑢,𝑣] Check whether 𝑙[𝑟,𝑣] can be matched to 𝑇
Algorithm Complexity Each limb in 𝑆[𝑣] corresponding to 𝑂 𝑙 𝑇 mbedding submatrix. A bipartite maximum matching for each limb imbedding submatrix. 𝑇𝑖𝑚𝑒=𝑂 𝑙 𝑥,𝑦 ∈𝑇 𝑙 𝑢,𝑣 ∈𝑆 𝑇𝑖𝑚𝑒 𝐻−𝐾 Submatrix of 𝑙[𝑢,𝑣] has deg(𝑢) rows and 𝑙 𝑇 columns, the corresponding bipartite graph has at most 𝑂 𝑙 𝑇 vertices and 𝑂 deg 𝑢 ⋅ 𝑙 𝑇 edges. 𝑇𝑖𝑚𝑒=𝑂 𝑙 𝑇 𝑙 𝑢,𝑣 ∈𝑆 deg 𝑢 ⋅ 𝑙 𝑇 3 2 =𝑂 𝑙 𝑇 5 2 ⋅ 𝑢∈𝑆 deg 𝑢 =𝑂( n t 5 2 𝑛 𝑠 )
Improve 𝑢∈𝑇 |𝑙 𝑇 𝑢 |≫|𝑙(𝑇)| Consider a rooted set 𝑇 𝑢,⋅
Improve 𝑆[ 𝑎 0 ,𝑏] can be matched to 𝑇[𝑢,𝑣] only if the corresponding edge can be contained in a maximum matching.
Improve Alternating path 图片来源:ws.nju.edu.cn/courses/gt/
Improve An edge can be used in a maximum matching if it is in an alternating path of even length on any maximum matching V1 V3 V2 V4 V6 V5 V7 原始图片来源:ws.nju.edu.cn/courses/gt/
Improved Algorithm Select 𝑟∈𝑙𝑒𝑎𝑣𝑒𝑠 𝑆 as the root vertex, decompose 𝑆[𝑟] into limbs Set the limbs imbedding submatrix for leaves in 𝑆[𝑟] (All leaves can be matched to any limbs in 𝑇) For 𝑙 𝑢,𝑣 ∈𝑆 𝑟 in a topological order(e.g. ordered by non-decreasing height) For each 𝑇 𝑢,⋅ Set the limbs imbedding submatrix by previous result. Build the corresponding bipartite graph Run H-K algorithm to find a maximum matching Search the graph to determine the set of vertices that the first row can reach by alternating path Check whether 𝑙[𝑟,𝑣] can be matched to 𝑇
Impreovd Algorithm Complexity Each limb in 𝑆[𝑣] corresponding to a rooted imbedding submatrix. A bipartite maximum matching for each limb imbedding submatrix. 𝑇𝑖𝑚𝑒=𝑂 𝑙 𝑢,𝑣 ∈𝑆 𝑇𝑖𝑚𝑒 𝐻−𝐾 Submatrix of 𝑙[𝑢,𝑣] has deg(𝑢) rows and no more than 𝑙 𝑇 columns, the corresponding bipartite graph has at most 𝑂 𝑙 𝑇 vertices and 𝑂 deg 𝑢 ⋅ 𝑙 𝑇 edges. 𝑇𝑖𝑚𝑒=𝑂 𝑙 𝑢,𝑣 ∈𝑆 𝑇 𝑢,⋅ deg 𝑢 ⋅deg 𝑥 3 2 =𝑂 𝑢∈𝑆 deg 𝑢 ⋅ 𝑥∈𝑇 deg(𝑥) 3 2 =𝑂( n t 3 2 𝑛 𝑠 )
Reference Matula D W. Subtree isomorphism in O (n 5/2)[J]. Annals of Discrete Mathematics, 1978, 2: 91-106. Conte D, Foggia P, Sansone C, et al. Thirty years of graph matching in pattern recognition[J]. International journal of pattern recognition and artificial intelligence, 2004, 18(03): 265-298. http://ws.nju.edu.cn/courses/gt/
Thanks Q&A
Tree Isomorphism For unrooted tree: 来源:http://perso.ens-lyon.fr/eric.thierry/Graphes2010/marthe-bonamy.pdf
Isomorphism via Sub-isomorphism Ordering via Structure Detection