简体   繁体   中英

Running time of Bucket sort

If we assume that the elements are uniformely distributed in a given range k, and we have 10 buckets. Then the amount of elements in each bucket will be the same after one iteration over the n elements in the list. Then for example we use quicksort to sort each of the buckets, but we know that the number of elements in each bucket are constant, so won't the total running time be Θ(n)?

No.

Puting the elements in 10 buckets is O(N).

Sorting one bucket with qsort is O(NlogN) (N/10 actually but constants don't matter for complexity).

So the overall complexity is going to be O(N + 10 * N logN) which is O(NlogN) (because N < NlogN and constants, 10, don't matter).

If this is too hard to understand try this way: If there were 2 buckets instead of 10, then you are doing exactly Qsort for the entire list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM