I just read the Wikipedia page about Bucket sort. In this article they say that the worst case complexity is O(n²). But I thought the worst case complexity was O(n + k) where k are the number of buckets. This is how I calculate this complexity:
- Add the element to the bucket. Using a linked list this is O(1)
- Going through the list and put the elements in the correct bucket = O(n)
- Merging the buckets = O(k)
- O(1) * O(n) + O(k) = O(n + k)
Am I missing something?