Linear Sort Algorithm

Bucket Sort

  1. Create m empty buckets (Or lists) in order.
  2. Split the data into the m buckets
  3. Sort each bucket internally using for example: quick sort or merge sort
  4. Concatenate all sorted buckets

With the assumption that the data can be uniformly distributed into the buckets, the time complexity as below:

  • step 2: O(n)
  • step 3: O(m * (n/m) log (n/m)) ≈ O(n) when m is closed to n
  • step 4: O(m)

So the total time complexity is O(n)
When the data is too big to fit into the memory, we can use bucket sort to split the data into small file firstly.

bucket-sort

Counting Sort

It is just a special case of bucket sort, which the number of bucket equal to the range of input data, so we don’t need to sort in each bucket.

  1. Get/Change the data rang, suppose from 0 to k
  2. Take a count array A to store the count of each unique object -> O(n)
  3. Modify the count array A such that each element at each index stores the sum of previous counts -> O(k)
  4. Output each object i from the input sequence based on the value of A[i] followed by decreasing A[i] by 1 -> O(n)

It can be used when k is not big, and the data range can be converted to non-negative integer.

counting-sort

Radix Sort

The idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort/bucket sort as a subroutine to sort which needs to be stable.

radix-sort

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值