merge sort

  1. After Quicksort, this is the second efficient sorting algorithm
  2. Merge Sort operates on the “divide and conquer” principle:
  3. first
  4. second
  5. The array is divided until arrays of length 1 are created
  6. the number of division stages is log2 n.
  7. On each merge stage, we have to merge a total of n elements (on the first stage n × 1, on the second stage n/2 × 2, on the third stage n/4 × 4, etc.):
  8. The merge process does not contain any nested loops, so it is executed with linear complexity: If the array size is doubled, the merge time doubles, too. The total effort is, therefore, the same at all merge levels.
  9. The time complexity of Merge Sort is: O(n log n)
  10. Merge Sort is therefore no faster for sorted input elements than for randomly arranged ones.
  11. For presorted elements, Merge Sort is about three times faster than for unsorted elements.
  12. For elements sorted in descending order, Merge Sort needs a little more time than for elements sorted in ascending order.
  13. Merge Sort is about three times faster for pre-sorted elements than for unsorted elements. However, the number of comparison operations differs by only about one third.
  14. not in-place
  15. a stable sorting process.
  16. In-Place Merge Sort


    If the element above the left merge pointer is less than or equal to the element above the right merge pointer, the left merge pointer is moved one field to the right.
    Otherwise, all elements from the first pointer to, but excluding, the second pointer are moved one field to the right, and the right element is placed in the field that has become free. Then both pointers are shifted one field to the right, as well as the end position of the left subarray.
  17. Merge Sort is an efficient, stable sorting algorithm with an average, best-case, and worst-case time complexity of O(n log n).

insert sort
18. With the outer loop, this is obvious as it counts up to n.
19. Average Time Complexity

  1. the time complexity for shifting is, therefore, O(n²). This is also called “quadratic time”.
  2. For comparison operations, we have one more than shift operations (or the same amount if you move an element to the far left). The time complexity for the comparison operations is, therefore, also O(n²).
  3. Worst-Case Time Complexity

    The term from the average case, therefore, changes in that the second dividing by two is omitted:
    6 × 5 × ½
    The worst-case time complexity of Insertion Sort is: O(n²)
  4. Best-Case Time Complexity
    If the elements already appear in sorted order, there is precisely one comparison in the inner loop and no swap operation at all.
  5. Insertion Sort With Binary Search?
    we would not have gained anything from this, because we would still have to shift each element from the insertion position one position to the right, which is only possible step by step in an array. Thus the inner loop would remain at linear complexity despite the binary search. And the whole algorithm would remain at quadratic complexity, that is O(n²).
  6. Insertion Sort With a Linked List?

If the elements are in a linked list, couldn’t we insert an element in constant time, O(1)?

Yeah, we could. However, a linked list does not allow for a binary search. This means that we would still have to iterate through all sorted elements in the inner loop to find the insertion position. This, in turn, would result in linear complexity for the inner loop and quadratic complexity for the entire algorithm.

stable
Insertion Sort is not directly parallelizable.* However, there is a parallel variant of Insertion Sort: Shellsort

  1. Insertion Sort is, therefore, not only faster than Selection Sort in the best case but also the average and worst case.

The reason for this is that Insertion Sort requires, on average, half as many comparisons. As a reminder, with Insertion Sort, we have comparisons and shifts averaging up to half of the sorted elements; with Selection Sort, we have to search for the smallest element in all unsorted elements in each step.

Selection Sort has significantly fewer write operations, so Selection Sort can be faster when writing operations are expensive. This is not the case with sequential writes to arrays, as these are mostly done in the CPU cache.

DS-fundation-sort1相关推荐

  1. 2021年大数据Spark(二十五):SparkSQL的RDD、DF、DS相关操作

      目录 RDD.DF.DS相关操作 SparkSQL初体验 SparkSession 应用入口 获取DataFrame/DataSet 使用样例类 指定类型+列名 自定义Schema ​​​​​​​ ...

  2. DS, ES, SS, DI, SI, BP, SP, IP, FS 寄存器

    为什么80%的码农都做不了架构师?>>>    DS, ES, SS, DI, SI, BP, SP, IP, FS 寄存器 DS is called data segment re ...

  3. DSAPI多功能组件编程应用-DS提示气泡

    首先下载DSAPI.dll.并在项目中引用. 该功能包括在DSAPI1.0.1.1及更高版本号,DLL请到本人资源里查找. Private Sub Button1_Click(sender As Ob ...

  4. Windows Server 2012 之配置AD DS

    在企业级的局域网络中,通常需要对其网络中的所有计算机统一管理,而传统的方式(用户组处于工作组模式)计算机之间互相不信任(不然会导致很明显的安全问题 总不至于要去信任一个***的电脑吧?) 为此需要一个 ...

  5. 确认AD DS域是否正常

    一.检查DNS服务器内的日志是否完整 1.检查主机日志: 域控dc1.sayms.com已经正确的将其主机名与ip地址注册到DNS服务器内 2.检查SRV日志--使用DNS控制台 数据类型为" ...

  6. Azure上A/D系列虚拟机到DS系列迁移(2)

    11. 该脚本会检测环境,停止虚拟机,拷贝VHD文件,创建磁盘等等,知道出现如下类似画面,他会暂停等待用户操作: 后面这几个步骤非常重要,关系到你后续的创建是否成功: 12. 进入D:\migvm目录 ...

  7. plspl和oracle,LOL2017LSPL春季死啊DS轻取NON ME逆转GD赢得首胜

    LOL2017LSPL春季死啊DS轻取NON ME逆转GD赢得首胜.2月9日,2017<英雄联盟>甲级职业联赛(LSPL)春季常规赛第二周继续进行,在当天的比赛当中,DS在两局比赛中击败N ...

  8. N-MOS的G-S电容随着DS电压的变化关系

    ➤ 01 栅极-源极输入电容与DS电压 对于 MOS管 往往存在较大的输入电容.这个电容随着DS的变化关系使得它可以当做一个可变电容来使用. 下面是IRF3710的数据手册的输入电容与DS电压之间的关 ...

  9. 对Exchange 事件ID 9154 DSACCESS 返回 DS 通知出现的错误“0x80004005”的处理

    环境: 1台主DC(2k3,集成DNS)5种操作主机角色都运行在主DC上,一台额外域控.           1台EX2K3 问题1:现EX2k3服务器上出现如下错误日志:             事 ...

  10. Windows 08 R2_创建AD DS域服务(图文详解)

    目录 目录 Active Directory概念 创建第一个AD域控制器 搭建DNS服务器 使用Windows窗口程序创建AD域控制器 AD与LDAP的关系 使用Powershell来创建ADDS域控 ...

最新文章

  1. .Net版InfluxDB客户端使用时的一些坑
  2. 光源时间_天哪!你们居然都错了!D65光源,指的是上午还是下午的太阳光?
  3. /dev/null 2>1 详解
  4. GPU Gems1 - 5 改良的Perlin噪声的实现
  5. type_traits应用
  6. Java验证(javafx)
  7. 小说中场景的功能_场景在小说中的作用
  8. 孙鑫-MFC笔记二--MFC框架剖析
  9. 【转】雅虎邮箱免费开通POP方法 YAHOO!MAIL YMAIL免费开通POP.SMTP和转发功能
  10. 深度学习笔记_术语/缩写/基本概念
  11. go实现json格式文件的输出---小示例
  12. python图书管理系统源代码_python实现 图书管理系统源码(入门级控制台项目)...
  13. 计算机创造奇迹的英语作文,大学英语作文:创造奇迹 Creating Miracle
  14. 2021年中国A2P(应用程序对个人)消息传递市场趋势报告、技术动态创新及2027年市场预测
  15. 口碑极好的SAP PP培训视频, 21G, 52个视频
  16. python小白逆袭大神_python小白逆天(3),Python,小白逆袭,大神,三
  17. 树莓派4B官方说明文档
  18. git使用及上传代码到github
  19. 一元稀疏多项式加减法计算器
  20. cmd下查询公网ip地址

热门文章

  1. Theia学习笔记(二)
  2. jupyter 执行代码出现ModuleNotFoundError: No module named pandas 问题
  3. android 三星调用拍照功能吗,Android 开发手机(三星)拍照应用照片旋转问题解决办法...
  4. PeopleSoft登录流程
  5. 小程序的图片上传wx.uploadFile及后台PHP接收文件并存储到服务器
  6. awk 学习(三) 应用示例+
  7. 玩转PPT 第1节 PPT制作理念学习笔记
  8. 手把手教你使用rand函数实现猜数字游戏
  9. 人工神经网络之神经网络的生理学背景
  10. 300dpi等于多少分辨率?如何给图片修改分辨率大小?