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

合并排序算法排序過程

外部分類 (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.pswp.cn/news/540918.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540918.shtml
英文地址,請注明出處:http://en.pswp.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創建線程之后,線程處于新建狀態,當調用…