My given sequence looks like this
<product, quantity>
<milk, 2>, <bread, 3>, <eggs, 3>, <sugar, 2>, <apples, 4>, <berries, 4>
Here I have my n value as 6 and k as 3 (3 distinct values - 2, 3, 4).
My sorted sequence should be like this. Sorted in increasing order of key-values
<milk, 2>, <sugar, 2>, <bread, 3>, <eggs, 3>, <apples, 4>, <berries, 4>
What algorithms can I use to sort this in two running times? 1. O(n) 2. O(nlogk)