常用排序算法总结与英文翻译

(1)选择排序:

中文:
    使用递归实现,递归结束条件:排序片段长度为1;
    递归函数:找到所给排序片段中最大的元素以及元素索引,将该元素置换到序列末尾,将排序长度减一调用递归函数。
    并且可以在外层循环中添加判断是否已经有序的终止条件来减少遍历次数。
英文:
    we can implement selection sort with recursion: when the length of piece which need to be sorted equal 1 , return; or we should foreach to find the maximal element and record its index, the swap the maximal element with the element at the end of the sequence , then call the recursion function use length-1. and we can add the end condition that judge whether the sequence has been sorted in the outer loop

(2)冒泡排序:

中文:
    将序列分为左右两部分,左边为无序部分,右边为有序。
    初始时右边长度为0,每一次遍历每个元素和相邻元素相比,将较大的元素交换到右边,逐渐将最大的元素交换到最右边,归属到右边部分(有序部分),左边部分长度-1。
    后续逐渐对左边进行上述遍历,直到左边长度为0。
英文:
    spilt the sequence into left part which is disorder and the right part which is in order. at the beginning , the length of the right part is 0, every element compare with the adjacent, swap the bigger to the right, gradually swap the biggest element to the far right of the left part . then the length of the left part sub 1. repeat mentioned above until the length of the left part equal 0.and we can add the end condition that judge whether the sequence has been sorted  in the outer loop.

(3)插入排序: 

中文:
    将序列分为左右两部分,左边为有序部分,右边为无序部分。
    初始时左边长度为1,每一次遍历就把右边的起始的元素a和依次从左边部分的末端与左边的元素进行比较,如果a较小,则继续向前比较,知道a>=左边的元素b时,将a插入到b后面。重复上述过程直到右边长度为0。
英文:
    split the sequence into the left part which is in order and the right part which is out of order. the inital value of the left part's length is 1, compare the first element of the right part with the element of the left part from the end of the left part foreach,if smaller, continue compare with the forword element of the left part, else insert this element behind the element of the left part compared just. repeat mentioned above until the length of the right part  is 0.

(4)原地重排序:

中文:
    分为两步:
    第一步,统计每个元素的实际排名,所有排名初始化为0,每个元素与其后面的元素相比,如果该元素比较大,则该元素的排名+1,否则与其相比的后面元素的排名+1;
    第二步,遍历排名数组,如果某个元素的排名r[i]和其所在索引i不相等,则先保存其排名为t,然后将其交换到排名所在的位置上(swap(a[r[i]], a[i]);),然后交换排名(swap(r[t], r[i]))。
英文:
    there are two steps in this method.first, we should count the actual rank of every element, which is initilized been 0, every element compare with other elements which behind it. if bigger, its rank add 1, else the other element's rank increase. second, iterate through the rank array, if r[i] unequal i,  save r[i] as t, then swap(a[r[i]], a[i]) and swap(r[t], r[i])。

(5)箱子排序:

中文:
    箱子排序是基于链表实现的,将要进行排序的链表中的值相同的节点放入到一个箱子中,每个箱子实际也是一个链表,箱子个数取决于要排序的值可能的范围大小,实际实现时,需要维护一个数组:
        每个元素对应一个箱子的头指针和尾指针,遍历原始链表结束后,遍历数组,按序将箱子链表头尾相接,即得到排序后的结果。
英文:
    the bin_sort is implemented based on the chainlist. put the node with same data into the  same bin. actually the bin is also a chainlist, the sum of the bins is decided on the range of the node's data. and when we implement this algrithom, we also need to keep a array. the element in this array is corresponding  a object which includes a bin's head pointer and a bin's end pointer. after putting all node into corresponding  bin, we just need to iterate the array and connect the bins by making the last bin's end pointer point to the next bin's head pointer, then we can get the sorted list.

(6)基数排序:

中文:
    将要进行排序的元素变为相等位数,较小的数字在高位补0,然后从低位开始逐渐对每一位进行箱子排序,最后即可得到排序结果。箱子个数取决于排序数字的进制。
英文:
    make the data needed to be sorted the same digits, filling 0 in the high position of the smaller number.  then carry on the binsort for every digit for the lowest digit. the we can get the sorted result. Add something that the number of the bins is decided on the data's radix.

(7)快排:

中文:
    核心思想是分治,可采用递归实现,每次将一个数字放置到其在有序序列中应在的位置。每次选择要进行排序的序列的首部元素作为基准,设置一个指针j从该序列尾部向前遍历,寻找第一个小于基准的数停止,再用另一个指针从序列首部开始向后遍历,寻找第一个大于基准的数。如果i和j相遇则停止遍历,将基准和指针j指向的元素进行交换,并以基准所在位置将序列分为左右两部分序列递归快排;否则将指针i和指针j所指向的元素进行交换,然后j继续向前遍历找下一个小于基准的数;i再向后遍历找下一个大于基准的数,直到i>=j。
英文:
    the center idea is  Dividing and conquering, we can implement the quick sort by recursion, we put one element on the correct place each time. choose the head element as the baseline, use a pointer j visit the element from the end to find the first number smaller than the baseline. the use the another pointer i visit the elements from the head to find the first number bigger than the baseline. During pointer i searching, if i meet j ,break and swap the baseline and the  number pointed by the pointer j. else swap the number pointed by i and the  number pointed by j, the j continue forward visit  ,the i visit backward until i >=j.

未完待续~(如有错误,欢迎指出~)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值