Optimal Pattern Matching on dDimensional Meshes