Optimizer searching for common patterns of elements