归并排序(Merge sort)

来源:互联网 发布:手机流量开关软件 编辑:程序博客网 时间:2024/06/08 03:13
  • Time complexity:O(logn)

  • 方法:二路归并(2-way merge)

  • 对象:有序序列(sorted sequence), 即可以是有序向量(sorted vector),也可以是列表(list)
  • 算法性质:迭代
  • 步骤
    1.无序向量的递归分解(递归)
    2.有序序列的逐层归并(迭代)

  • 算法描述:(摘自Oxford一哥们写的DS教材~)

    Divide and conquer
    Merge sort has three steps to sort an input sequence S with n elements:

    1. Divide—partition S into two sequences S1 and S2 of about n/2 elements each
    2. Recur—recursively sort S1 and S2
    3. Conquer—merge S1 and S2 into a sorted sequence
0 0