Find similar elements and group them.