Time complexity n=length[A] 1 time f or i=1 to n n times do insert A[i] into bucket B[n A[i]] O(n) f or i=0 to n-1 n times do sort bucket B[i] with insertion sort ∑O(n^2) Concatenate bucket O(n)
Best Case In the best case every element belongs to different buckets so the complexity is O( n+k ) Where n=number of elements and k is the number of buckets
Average Case In average case running time of bucket sort is: T(n)= Θ (n)+∑O(n^2) So the average c omplexity is O( n+k )
Worst Case In worst case complexity is O(n^2), as every element belongs to one bucket so we have to use insertion sort n elements. Instead of insertion sort we could merge or heap sort because their worst case running time is O(n log n). But we use insertion sort because we expect the buckets to be small and insertion sort works much faster for small array.