当前位置:网站首页>External sort
External sort
2022-06-13 04:59:00 【Be nice 123】
External sorting
External sorting
External storage , Data exchange between memory

The principle of external sorting
The size of each buffer should be equal to the size of the disk block
Multi channel balanced merging
There is only one buffer empty , It should be immediately filled with the next piece of the merged paragraph , Instead of directly 27 Output to output buffer
The merged results will be written to another space on the disk , And release the original space , Here, the merged results are moved to the original space in the view to demonstrate the beauty


Increase the number of ways to merge , Reduce the number of merging trips , This can reduce the number of times to read and write to the disk
Loser tree
Some books call the position of Tianjin rice in the loser tree the root node , Some people call the location of Sunwukong the root node
Now there are the following 8 A merge segment , Select the smallest data element each time , Every smallest element needs to be selected 7 Second comparison . To reduce the number of comparisons , We can build a loser tree first .
Each leaf node in the loser tree below corresponds to a merge segment
At these failed nodes ( That is, the grey node in the loser tree ) Usually, the merging segment from which the failed element is recorded , The following screenshot is for convenience , So it's the value of the element , In fact, the gray node should be used to store the merging segment from which the competing elements failed
The correct node records are as follows , That is, the gray node records which merging segment the loser comes from , The root node records the champion ( The final winner of the competition ) From which merging segment
Merge for the first time , Contrast 7 We found the smallest element from which merge segment . Next, according to the rules of merging and sorting , We also need to merge 1~8 Select the next smallest element in the . Next, we'll let the merging section 3 The next element of replaces 1 The original position of this element
Next, select the new smallest element from the remaining leaf nodes , We just need to let 6 Compare with the smallest element in the fourth merging segment
As long as the loser tree is constructed , Next, each time you select the smallest element , Just compare 3 Time , That is, the number of grey nodes of the loser tree
Suppose we have built a loser tree , Tree height is h(h Blue nodes are not included , It's a tree of grey and green nodes ). Is the first h There are 2 h − 1 2^{h-1} 2h−1 Nodes
k The loser tree of the road merger will have k Leaf node . So there should be k < = 2 h − 1 k <= 2^{h-1} k<=2h−1
Solution h − 1 = ⌈ log 2 k ⌉ h -1=\lceil\log_2k\rceil h−1=⌈log2k⌉ . and h-1 It just represents how many layers the branch node has . As mentioned before, the number of layers of a branch node needs to be compared , So with the loser tree , Choose the smallest element , Just compare keywords ⌈ log 2 k ⌉ \lceil\log_2k\rceil ⌈log2k⌉ Time
If it is 1024 Road merging , Then the traditional method , It's going to happen every time 1023 Compare it to , The loser tree only needs comparison ⌈ log 2 1024 ⌉ \lceil\log_21024\rceil ⌈log21024⌉ namely 10 Second comparisonThe array index is zero 1 The element of corresponds to the root node in the traditional sense , The array index is zero 0 Corresponding to the newly added small head ls[0]. Leaf nodes do not correspond to any data in the actual array . Logically , Each green leaf node corresponds to a merge segment , In fact, these leaf nodes are made up by our brain
substitution - Selection sort ( Generate initial merge segment )
The best merging tree
边栏推荐
- Analysis of the principle of V-model and its application in user defined components
- 2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
- RTSP streaming using easydarwin+ffmpeg
- Section 5 - Operator details
- Autumn wind, dust, youth
- C language learning log 10.11
- Flutter dart variables and constants
- OJ problem solution summary
- Little C's Notepad
- Section 8 - Practical commissioning techniques
猜你喜欢

Bomb disposal cat

Analysis on the similarities and differences of MVC, MVP and mvvc

QT interface rendering style

Draw a hammer

Brick story

Advanced C - Section 2 - pointers

Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution論文淺析

Section 2 - branch and loop statements

PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes

Mysql8.0.13 installation tutorial (with pictures)
随机推荐
Bomb disposal cat
C language exercise 1
D 小红的构造题
Win8.1和Win10各自的优势
【JS解决】leedcode 200. 岛屿数量
E - Lucky Numbers
Solution to sudden font change in word document editing
C language learning log 10.4
C language learning log 1.16
Robot pose description and coordinate transformation
JS to realize the conversion between string and array and an interview question
Shell built-in string substitution
QT client development -- driver loading problem of connecting to MySQL database
Spice story
Mysql8.0.13 installation tutorial (with pictures)
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Analysis of the principle of V-model and its application in user defined components
Nodejs parsing get request URL string
自动评教脚本使用的配置
Section 8 - Practical commissioning techniques





















