I have a database in array list and I need to sort them in ascending order based on the frequency of the items, not on lexicographic order.
E.g. Each row is an array with the items
1 2 9
1 2 3 4 5
1 6 7 8
will be arranged into
9 2 1
3 4 5 2 1
6 7 8 1
E.g. in row 1, item 1 is at the last because it has the highest frequency (3), follow by item 2 whose frequency is 2.
Given that I have a large database, is there any way to efficiency sort them? Thanks for your help!