Write a method named guavaSort
that accepts an array of strings as a parameter and arranges the strings in the array into sorted ascending order. Specifically, your sorting algorithm should use a Guava Multiset
or Multimap
to implement a variation of the bucket sort algorithm that will work on strings. Use the Guava collection to count occurrences of strings, similarly to what is done in bucket sort, and then place those strings back into the array in sorted order. For example, suppose your method is passed the following array:
[Farm, Zoo, Car, Apple, Bee, Golf, Bee, Dog, Golf, Zoo, Zoo, Bee, Bee, Apple]
Your collection should store the following occurrences of the strings:
[Apple x 2, Bee x 4, Car, Dog, Farm, Golf x 2, Zoo x 3]
Which you should use to put the strings back into the array in sorted order:
[Apple, Apple, Bee, Bee, Bee, Bee, Car, Dog, Farm, Golf, Golf, Zoo, Zoo, Zoo]
Your code should run in O(N log N) time and use O(N) memory, where N is the number of elements in the array.
You may assume that the array passed, and all of the strings in it, are not null
.
Do not construct any other auxiliary collections other than the single Multiset
or Multimap
.