Radix sort vs Counting sort vs Bucket sort. What's the difference?

前端 未结 7 1135
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 21:50

I am reading the definitions of radix, counting and bucket sorts and it seems that all of them are just the code below:

public static void sort(int[] a, int maxV         


        
7条回答
  •  隐瞒了意图╮
    2021-01-29 21:54

    Radix sort vs Counting sort vs Bucket sort. What's the difference?

    Bucket sort places the keys or elements to be sorted into buckets. How they are places in buckets is arbitrary and can be portions of a composite key and any distribution you like. The individual buckets may need to sort further.

    Sorting in memory is faster than sort on disk. However if you have more data than will fit in memory you need another option. What you can do is a bucket sort, where the buckets are small enough to fit into memory. i.e. there is a large number of entries in each bucket. These you can quick sort individually.

    Radix sort is a specific type of bucket sort. It starts with the top n-bit or n-digits and may sort those buckets using a radix sort etc, until every entry is sorted.

    Counting sort is like using radix sort except you are using the whole value. Instead of recording each object, it has a bucket for each object and it just counts the number of occurrences. This works well when you have a limited number of possible keys and you have many duplicates.

提交回复
热议问题