sort elements by frequency