合并排序算法排序过程

外部分类 (External sorting)

External sorting is a technique in which the data is stored on the secondary memory, in which part by part data is loaded into the main memory and then sorting can be done over there. Then this sorted data will be stored in the intermediate files. Finally, these files will be merged to get a sorted data. Thus by using the external sorting technique, a huge amount of data can be sorted easily. In case of external sorting, all the data cannot be accommodated on the single memory, in this case, some amount of memory needs to be kept on a memory such as hard disk, compact disk and so on.

外部排序是一种将数据存储在辅助存储器中的技术,其中,将部分数据加载到主存储器中,然后可以在那里进行排序。 然后,将这些排序后的数据存储在中间文件中 。 最后,这些文件将合并以获得排序的数据。 因此,通过使用外部分类技术,可以轻松地分类大量数据。 在进行外部排序的情况下,所有数据都无法容纳在单个内存中,在这种情况下,需要在硬盘,光盘等内存中保留一定数量的内存。

The requirement of external sorting is there, where the data we have to store in the main memory does not fit into it. Basically, it consists of two phases that are:

存在外部排序的要求,我们必须存储在主存储器中的数据不适合其中。 基本上,它包括两个阶段:

  1. Sorting phase: This is a phase in which a large amount of data is sorted in an intermediate file.

    排序阶段:这是在中间文件中对大量数据进行排序的阶段。

  2. Merge phase: In this phase, the sorted files are combined into a single larger file.

    合并阶段:在此阶段,已排序的文件被合并为一个较大的文件。

One of the best examples of external sorting is external merge sort.

外部排序的最佳示例之一是外部合并排序。

外部合并排序 (External merge sort)

The external merge sort is a technique in which the data is stored in intermediate files and then each intermediate files are sorted independently and then combined or merged to get a sorted data.

外部合并排序是一种技术,其中数据存储在中间文件中,然后将每个中间文件独立排序,然后合并或合并以获得排序后的数据。

For example: Let us consider there are 10,000 records which have to be sorted. For this, we need to apply the external merge sort method. Suppose the main memory has a capacity to store 500 records in a block, with having each block size of 100 records.

例如:让我们考虑必须对10,000条记录进行排序。 为此,我们需要应用外部合并排序方法。 假设主存储器具有在一个块中存储500条记录的容量,每个块的大小为100条记录。

In this example, we can see 5 blocks will be sorted in intermediate files. This process will be repeated 20 times to get all the records. Then by this, we start merging a pair of intermediate files in the main memory to get a sorted output.

在此示例中,我们可以看到5个块将在中间文件中排序。 此过程将重复20次以获取所有记录。 然后,我们开始在主存储器中合并一对中间文件,以获得排序后的输出。

两路合并排序 (Two-Way Merge Sort)

Two-way merge sort is a technique which works in two stages which are as follows here:

双向合并排序是一项分两个阶段工作的技术,如下所示:

Stage 1: Firstly break the records into the blocks and then sort the individual record with the help of two input tapes.

阶段1 :首先将记录分成多个块,然后借助两个输入磁带对单个记录进行排序。

Stage 2: In this merge the sorted blocks and then create a single sorted file with the help of two output tapes.

第2阶段 :在此合并排序的块,然后借助两个输出磁带创建单个排序的文件。

By this, it can be said that two-way merge sort uses the two input tapes and two output tapes for sorting the data.

这样,可以说双向合并排序使用两个输入磁带和两个输出磁带对数据进行排序。

双向合并排序算法: (Algorithm for Two-Way Merge Sort:)

Step 1) Divide the elements into the blocks of size M. Sort each block and then write on disk.

步骤1)将元素划分为大小为M的块。对每个块进行排序,然后写入磁盘。

Step 2) Merge two runs

步骤2)合并两次跑步

  1. Read first value on every two runs.

    每两次运行读取第一个值。

  2. Then compare it and sort it.

    然后对其进行比较和排序。

  3. Write the sorted record on the output tape.

    将排序的记录写在输出磁带上。

Step 3) Repeat the step 2 and get longer and longer runs on alternates tapes. Finally, at last, we will get a single sorted list.

步骤3)重复步骤2,并在备用磁带上运行的时间越来越长。 最后,最后,我们将获得一个排序列表。

Analysis

分析

This algorithm requires log(N/M) passes with initial run pass. Therefore, at each pass the N records are processed and at last we will get a time complexity as O(N log(N/M).

该算法需要log(N / M)遍及初始运行遍。 因此,每遍处理N条记录,最后我们得到的时间复杂度为O(N log(N / M)

翻译自: https://www.includehelp.com/algorithms/external-merge-sorting.aspx

合并排序算法排序过程

合并排序算法排序过程_外部合并排序算法相关推荐

  1. Kmeans算法的过程是什么?Kmeans算法的缺陷主要有哪些?

    Kmeans算法的过程是什么?Kmeans算法的缺陷主要有哪些? 目录 Kmeans算法的过程是什么?Kmeans算法的缺陷主要有哪些?

  2. 希尔排序的详细过程_算法系列: 10大常见排序算法(4)希尔排序

    本课程是从少年编程网转载的课程,目标是向中学生详细介绍计算机比赛涉及的编程语言,数据结构和算法.编程学习最好使用计算机,请登陆 www.3dian14.org (免费注册,免费学习). 一句 希尔排序 ...

  3. 本题要求实现一个用选择法对整数数组进行简单排序的函数。_通俗易懂讲 Python 算法:快速排序...

    原文:https://stackabuse.com/quicksort-in-python/ 作者:Marcus Sanatan 译者:老齐 欢迎在 bilibili  搜索 freeCodeCamp ...

  4. 社区发现算法python视频_社区发现FN算法Python实现

    社区发现FN算法Python实现 算法原理 评价指标 结果对比 源码 ​2004年,Newman在GN(Girvan and Newman, 2002)算法的基础上,提出了另外一种快速检测社区的算法, ...

  5. 蚁群算法java实现_简单蚁群算法 + JAVA实现蚁群算法

    一 引言 蚁群算法(ant colony optimization,ACO),又称蚂蚁算法,是一种用来在图中寻找优化路径的机率型技术.它由Marco Dorigo于1992年在他的博士论文中引入,其灵 ...

  6. 银行家算法是什么_什么是银行家算法?

    银行家算法是什么 Banker's algorithm is a deadlock avoidance algorithm. It is named so because this algorithm ...

  7. python贝叶斯算法的论文_朴素贝叶斯算法从入门到Python实践

    1,前言 很久不发文章,整理些干货,希望相互学习吧.进入主题,本文主要时说的为朴素贝叶斯分类算法.与逻辑回归,决策树一样,是较为广泛使用的有监督分类算法,简单且易于理解(号称十大数据挖掘算法中最简单的 ...

  8. 图论算法 最短路程_从网页排序看图论的重要应用

    从网页排序|看图论的重要应用 图,是什么? 现实生活中很多问题都可以用图进行描述, 如网络流.资源分配.电路优化.网页排序.搜索.工序安排等等. 同时, 图也是描述许多数据结构的重要手段, 如树结构是 ...

  9. 名词解释 算法的有限性_欲借助 FFT 算法快速计算两有限长序列的线性卷积,则过程中要调用 ( ) 次 FFT 算法_学小易找答案...

    [单选题]计算 N=2 L ( L 为整数)点的按时间抽取基 -2FFT 需要 ( ) 级蝶形运算 [单选题]Les étudiants chinois, une fois arrivés en Fr ...

最新文章

  1. 使用Leangoo玩转故事地图
  2. delphi存取图片
  3. mysql5.6.28安装教程百度经验_Linux(Ubuntu)下Mysql5.6.28安装配置方法图文教程
  4. pthread-win32 semaphore信号量总结
  5. js技巧收集(200多个)
  6. java 线程等待_代码分析Java中线程的等待与唤醒
  7. 数据库并发抢红包_Redis悲观锁解决高并发抢红包的问题
  8. python爬虫淘宝评论图片_淘宝上的图片是怎么被爬取的
  9. Linux中vim命令详解
  10. ionic 中使用 slidebox 利用angular ng-repeat 渲染后不显示问题
  11. mysql中将大写日期转为小写日期
  12. iOS-[NSAttributedString]设置富文本和计算富文本高度
  13. Unhandled promise rejection错误解决
  14. 做开发3年,字节跳动二面JVM底层被问得哑口无言
  15. c语言 求单元格中间某段字符串,EXCEL怎么取单元格里面的的值的中间某些字符...
  16. 3.2 数值分析: Jacobi与Gauss-Seidel迭代法
  17. Java 压缩/混淆 JavaScript 代码
  18. Java并发编程-Exchange
  19. 数据分析指标大收集!互联网行业必备!
  20. go break跳出两层for循环

热门文章

  1. n个结点,不同形态的二叉树(数目+生成)
  2. hdu1962Corporative Network带权回路
  3. (2021) 25 [持久化] 文件系统实现:FAT和UNIX文件系统
  4. 计算机组装过程英文版,计算机组装与维护试题及答案(国外英文资料).doc
  5. python删除文件和linux删除文件区别_使用Python批量删除文件列表
  6. mysql对称连接什么意思_对称加密与非对称加密的区别是什么
  7. microbit编程_使用图形化编程实现主控板与手机蓝牙通讯(2019.3.25)
  8. c语言提取七位数讲解,C语言-体育彩票7位数,感受身中500万的fell
  9. C#异或运算符的使用【C#】
  10. UVA - 1339 ​​​​​​​Ancient Cipher