合并排序算法排序过程_外部合并排序算法

合并排序算法排序过程

外部分类 (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条记录。

External Merge Sorting Algorithm 1

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,并在备用磁带上运行的时间越来越长。 最后,最后,我们将获得一个排序列表。

External Merge Sorting Algorithm 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

合并排序算法排序过程

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540918.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php榛子云短信验证,java + maven +榛子云短信 实现发送短信验证码功能

如何使用java maven的项目环境发送短信验证码,本文使用的是榛子云短信的接口。下载下来是jar文件,需要将jar发布到本地的maven仓库中, 在cmd环境下输入:mvn install:install-file -DgroupIdcom.zhenzi -DartifactIdsms -Dversion1.0.0 -Dpac…

django css_在应用程序上实现CSS Django的

django cssCSS (Cascade Style Sheets) are used to implement design. CSS(级联样式表)用于实现设计。 Step 1: Create a Sandbox, Activate it, Install Django and Create Sample Project 步骤1:创建一个沙箱,将其激活,安装Django并创建示…

PHPWeb开发入门体验学习笔记

PHPWeb开发入门体验学习笔记4一、PHP web应用开发须知1.入门要点程序员三个阶段:码农(速成技能)->工程师(长期知识)->专家(研究论文)编程三要素:声明变量(系统、全…

vb mysql 表格显示,在VB中编辑数据库和电子表格

在VB50中有很多功能强大的控件,其中数据控件与一些绑定控件(如文本框,图片框及 ActiveX控件)的相互协作,能够方便地实现对各种数据库记录、表格乃至电子表格的浏览和编辑操作。下面介绍实例,其中数据控件用于记录的浏览、移动、…

c# datetime._C#| DateTime.AddTicks()方法与示例

c# datetime.DateTime.AddTicks()方法 (DateTime.AddTicks() Method) DateTime.AddTicks() method is used to return a new date-time object that adds ticks value of this instance. This object does not change the original value of date-time but it returns an objec…

12345组成三个不重复数java,求大神帮忙!五子棋!只能识别按顺序识别!例如 12345 不能...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼import java.util.Arrays;import java.util.Scanner;public class Gobang {public static void main(String[] args) {Scanner sc new Scanner(System.in);boolean finish false;// 有戏是否结束int flagNum 1;// 当前下棋者标记…

[转]Visual Studio 各版本下载

原文地址:[置顶] Visual Studio 各版本下载 文件名称文件大小百度网盘下载微软官方下载Visual Studio 2015 Enterprise - 企业版 - 简体中文3.89GBhttp://pan.baidu.com/s/1bnAY68Bvs2015.ent_chs.isoVisual Studio 2015 Professional - 专业版 - 简体中文3.84GBht…

JavaScript中的“ this”关键字

JavaScriptthis关键字 (JavaScript this keyword) The this keyword is widely used in JavaScript. It has many use cases and is also one of the most intimidating features of JavaScript. In most of the programming languages, this is used to refer to the current …

oracle 列级外键,Oracle外键列上是否需要索引?

外键列上缺少索引会带来两个问题,限制并发性、影响性能。而这两个问题中的任意一个都可能会造成严重性能问题。 无论是Or外键列上缺少索引会带来两个问题,限制并发性、影响性能。而这两个问题中的任意一个都可能会造成严重性能问题。无论是Oracle的官方文…

python 改变词典顺序_按词典顺序排列的功率集

python 改变词典顺序Description: 描述: This is a standard interview problem to find out the power sets in lexicographic order of a given set of numbers using backtracking. 这是一个标准的面试问题,它使用回溯来按给定数字集的字典顺序查找能…

oracle创建用户名了,oracle创建用户名

创建用户//创建用户名create user username identified by password‘’//赋权限Grant Connect,Resource,DBA to UserName;plsql developer配置下载地址http://ah1.down.chinaz.com/201011/plsql8.04cn.zip右击"我的电脑" - "属性" - "高级" - &…

webpack学习笔记1

webpack学习笔记1:基本概念 前言: 现在在日常的开发中,webpack已经是必不可少的东西了,现在的需求基本都是用webpack对资源进行打包整合,所以打算写一点关于webpack的东西,这是第一篇,主要是介绍…

ruby 嵌套函数_Ruby嵌套有示例的循环

ruby 嵌套函数嵌套循环 (Nested for loop) Nesting of for loop means one for loop is available inside another for loop. It means that there are two loops, then the first one is an outer loop and the second one is the inner loop. Execution will take place in t…

oracle10数据库链接失败,Oracle10g出现Enterprise Manager 无法连接到数据库实例解决办法...

刚装好 10g 时,把的监听端口是1521.后来把端口改成了1568了,登上em发现Enterprise Manager 无法连接到数据库实例 ,连接字符串的端口仍是1521,如何解决这个问题。登陆:出现下面错误:Enterprise …

springJdbc in 查询,Spring namedParameterJdbcTemplate in查询

springJdbc in 查询,Spring namedParameterJdbcTemplate in查询, SpringJdbc命名参数in查询,namedParameterJdbcTemplate in查询 >>>>>>>>>>>>>>>>>>>>>>>>>>…

oracle 11g r2版本号,Oracle 11g r2新增版本功能(二)

在11.2中,Oracle数据库引入的版本的概念,这为应用程序的升级提供了极大的方便。这篇简单描述版本的实现和查询方式。前一篇简单描述了版本,下面接着上面的例子看看Oracle是如何实现这个功能的:SQL> select synonym_name, table…

python 添加图例_Python | 在图例标签中添加Sigma

python 添加图例Sigma (𝜎) is very often used greek mathematical letters and has a higher repetition in probability. In this article, we are going to add 𝜎 using a command in matplotlib. Sigma(𝜎)是希腊数学字母中经常使用的字…

【51CTO学院】搜索V2.0——新的搜索,只为给你更好的

为了让你能快速、准确的找到自己心仪的内容,51CTO学院产品及研发用尽了洪荒之力研发近2个月终于将搜索进行了全面升级。 搜索看似简单,实则要做到精准和智能却不是件易事,为了让学员快速找到自己所需,节省找课时间,更高…

oracle扩容日志文件,ORACLE 加大日志文件

--新建临时日志文件alter database add logfile group 4 (‘/u01/app/oracle/oradata/orcl/redo04.log‘) size 10m;alter database add logfile group 5 (‘/u01/app/oracle/oradata/orcl/redo05.log‘) size 10m;alter database add logfile group 6 (‘/u01/app/oracle/orad…

java多线程总结(二)

线程一般有6个状态: 新建状态:NEW 可运行状态:RUNNABLE 休眠状态:TIMED_WAITING 等待状态:WAITING 阻塞状态:BLOCKED 终止状态“TERMINATED 当我们使用new创建线程之后,线程处于新建状态,当调用…