资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PostgreSQL中REPLACEMENTSELECTIONSORT使用与哪种情况

本篇内容主要讲解“PostgreSQL中REPLACEMENT SELECTION SORT使用与哪种情况”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“PostgreSQL中REPLACEMENT SELECTION SORT使用与哪种情况”吧!

创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站建设、襄汾网络推广、重庆小程序开发公司、襄汾网络营销、襄汾企业策划、襄汾品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供襄汾建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

REPLACEMENT SELECTION SORT,适用于内存较小的情况(在高德纳提出该算法的年代,内存比起现在少了N个数量级).
该算法在PG 9.x或以下版本在使用,在高版本已被废弃.其算法实现如下:

Let m be the number of records to be sorted which can be kept in the main memory. Imagine that these memory locations are registers and assume we can mark them as “on” or “off”. Replacement selection can overlap reading, sorting and writing.

Step1: The m registers are filled with records from the input to be sorted.
Step2: All registers are put into the “on” state.
Step3: Select the register which has the smallest of all “on” registers.
Step4: Transfer the contents of the selected register to the output (call it as key Y).
Step5: Replace the contents of the selected register by the next input record.
            If new record key > Y
                        Go to step 3
            If new record key = =Y
                        Go to step 4
            If new record key < Y
                        Go to step 6
Step6: Turn the selected key register  “off”.
            If all registers are now  “off”
                        We have completed a sorted substring(run).
                        We start a new substring group and go to step 2.
            Else
                        Go to step 3

下面是该算法的一个例子:

Example: Suppose number of registers is 3 and input keys are 5, 2, 9, 7, 0, 8, 1, 6, 3, 4 ...
            Registers                               Output
            5 2 9                                       2
            5 7 9                                       5
*0 7 9                                     7
*0 8 9                                     8
*0*1 9                                    9
*0*1*6
0 1 6                                       0
3 1 6                                       1
3 4 6                                       3
- 4 6                                        4
- - 6                                        6
- - -

相关的数据结构:两个数组,一个存储读取的实际数据,一个标记数组;一个外存,用于存储已完成排序的一个run.
如标记数组全为F(非活动状态),则产生一个run,周而复始,直至所有输入被耗尽为止.
通过这个方法,可以生成N个runs(每个run对应的是已完成排序的部分数据).

CS 351 -Data Organization and Management ( Section: 02)
External_sorting
replacement-selection-sort vs selection-sort

到此,相信大家对“PostgreSQL中REPLACEMENT SELECTION SORT使用与哪种情况”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


分享标题:PostgreSQL中REPLACEMENTSELECTIONSORT使用与哪种情况
分享链接:http://cdkjz.cn/article/gpceji.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220