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?
O(1)
performance. However, either way, you'll need eventually to sort the individual bucket, which is where (I think) the worst-caseO(n^2)
performance comes from. – Jyoti