CN105574344A - Pyramid sorting algorithm - Google Patents

Pyramid sorting algorithm Download PDF

Info

Publication number
CN105574344A
CN105574344A CN201510975288.9A CN201510975288A CN105574344A CN 105574344 A CN105574344 A CN 105574344A CN 201510975288 A CN201510975288 A CN 201510975288A CN 105574344 A CN105574344 A CN 105574344A
Authority
CN
China
Prior art keywords
data
array
pyramid
sorting
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201510975288.9A
Other languages
Chinese (zh)
Inventor
吕勇
刘斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Changzhou College of Information Technology CCIT
Original Assignee
Changzhou College of Information Technology CCIT
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Changzhou College of Information Technology CCIT filed Critical Changzhou College of Information Technology CCIT
Priority to CN201510975288.9A priority Critical patent/CN105574344A/en
Publication of CN105574344A publication Critical patent/CN105574344A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G16INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR SPECIFIC APPLICATION FIELDS
    • G16ZINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR SPECIFIC APPLICATION FIELDS, NOT OTHERWISE PROVIDED FOR
    • G16Z99/00Subject matter not provided for in other main groups of this subclass

Landscapes

  • Complex Calculations (AREA)

Abstract

The invention discloses a pyramid sorting algorithm. According to the pyramid sorting algorithm, firstly, an integer m being integral power of 2 is found, and n is larger than m/2 and smaller than or equal to m; then n data required to be sorted are placed into a b array; adjacent data in the b array are compared one by one, and relatively larger subscripts are placed in a (m/2)-(m-1) unit of a c array; adjacent data in b[c[m-1]]-b[c[m/2]] are compared one by one, relatively larger subscripts are placed in c[m/2-1]-c[m/4], and so on; finally, subscripts of maximum data of the whole b array can be placed in c[1]; then maximum values in the b array are found out continuously, and sorting is completed. Under the condition that to-be-sorted sequences are basically sorted, the sorting speed of the pyramid sorting algorithm is obviously superior to that of quick sorting; under the condition that to-be-sorted elements adopting a more complicated data structure are sorted, the sorting speed of the pyramid sorting algorithm is obviously superior to that of heap sorting.

Description

A kind of pyramid sort algorithm
Technical field
The present invention relates to a kind of pyramid sort algorithm.
Background technology
Current, when sorting to mass data, what usually select is quick sorting algorithm.Quicksort is the sort algorithm of excellent performance, but if quicksort reference value selects improper or when collating sequence is substantially orderly, the performance of quicksort can significantly reduce.And heapsort is faster than quicksort when treating that collating sequence is substantially orderly, but heapsort also has shortcoming: when until collation element being complicated data structure, because mobile number of times invalid in heapsort is many, also has considerable influence to heapsort performance.
Summary of the invention
The object of this invention is to provide a kind of pyramid sort algorithm, treating in the basic situation in order of collating sequence and when treating that collation element has complicated data structure, promoting sequencing production.
The technical scheme realizing the object of the invention is: a kind of pyramid sort algorithm, comprises the following steps:
1., when sorting to n data, first define a array that has n unit, then find an integer m, m is the integral number power of 2, and m/2 < n≤m;
2., define the b array that has m unit, b array forms pyramidal column foot; Define the c array that has m unit again, c array forms pyramidal tower body;
3., to c array carry out initialization, will n data of sequence be needed to put into b array, and in b array, put into m-n minimum value data, these minimum value data be the minimum value data in n data, form m/2 to adjacent data; Then it compared one by one, the subscript of relatively large number is put into m/2 ~ m-1 unit of c array, this process forms pyramid the 1st layer of tower body;
4., from m-1, compare one by one b [c [m-1]] and b [c [m-2]], b [c [m-3]] and b [c [m-4]] ..., b [c [m/2+1]] and b [c [m/2]], and the subscript of relatively large number is put into c [m/2-1], c [m/2-2] ..., in c [m/4], the rest may be inferred forms pyramid the 2nd, the 3rd ... and even maximum layer tower body, build whole tower body thus, the lower rotating savings of last whole b array maximum value data is placed in c [1];
5. the maximum value data in the b array, 4. obtained for step is composed with minimum value;
6., repeat step 4. with step 5., thus constantly find out the maximal value in b array, and it put into one by one a [0], a [1], a [2] ..., complete sequence.
Described step 1. in the method for searching of integer m be: be 1 to a variable assignments, then compare the value of this variable and n, if it is less than n, then be multiplied by 2, again compared the value of it and n ... until these data are more than or equal to n, now the value of this variable is m.
Described step 3. in adjacent data refer to down that the data that are designated as odd number and the data before it are adjacent data, be not adjacent data with the data after it.
Have employed technique scheme, the present invention has following beneficial effect: the present invention's sequencing production is under normal conditions a little less than quicksort, but treating in the basic situation in order of collating sequence, sequencing production of the present invention is obviously better than quicksort, and when treat collation element be more complicated data structure sort, sequencing production of the present invention is obviously better than heapsort.
Embodiment
(embodiment 1)
The pyramid sort algorithm of the present embodiment, comprises the following steps:
1., when sorting to n data, first define a array that has n unit, then find an integer m, m is the integral number power of 2, and m/2 < n≤m.
The method for searching of integer m is: be 1 to a variable assignments, then compares the value of this variable and n, if it is less than n, is then multiplied by 2, again compares the value of it and n ..., until these data are more than or equal to n, now the value of this variable is m.
2., define the b array that has m unit, b array forms pyramidal column foot; Define the c array that has m unit again, c array forms pyramidal tower body.
3., to c array carry out initialization, will n data of sequence be needed to put into b array, and in b array, put into m-n minimum value data, these minimum value data be the minimum value data in n data, form m/2 to adjacent data; Then it compared one by one, the subscript of relatively large number is put into m/2 ~ m-1 unit of c array, this process forms pyramid the 1st layer of tower body.
Adjacent data refers to down that the data that are designated as odd number and the data before it are adjacent data, not adjacent data with the data after it, namely b [2i] and b [2i+1] is adjacent data (wherein i is integer), and b [2*i] and b [2*i-1] is not adjacent data.Such as b [0] and b [1] are adjacent datas, and b [1] and b [2] is not adjacent data.
4., from m-1, compare one by one b [c [m-1]] and b [c [m-2]], b [c [m-3]] and b [c [m-4]] ..., b [c [m/2+1]] and b [c [m/2]], and the subscript of relatively large number is put into c [m/2-1], c [m/2-2] ..., in c [m/4], the rest may be inferred forms pyramid the 2nd, the 3rd ... and even maximum layer tower body, build whole tower body thus, the lower rotating savings of last whole b array maximum value data is placed in c [1].
5. the maximum value data in the b array, 4. obtained for step is composed with minimum value.
6., repeat step 4. with step 5., thus constantly find out the maximal value in b array, and it put into one by one a [0], a [1], a [2] ..., complete sequence.
Above-described specific embodiment; object of the present invention, technical scheme and beneficial effect are further described; be understood that; the foregoing is only specific embodiments of the invention; be not limited to the present invention; within the spirit and principles in the present invention all, any amendment made, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (3)

1. a pyramid sort algorithm, is characterized in that: comprise the following steps:
1., when sorting to n data, first define a array that has n unit, then find an integer m, m is the integral number power of 2, and m/2 < n≤m;
2., define the b array that has m unit, b array forms pyramidal column foot; Define the c array that has m unit again, c array forms pyramidal tower body;
3., to c array carry out initialization, will n data of sequence be needed to put into b array, and in b array, put into m-n minimum value data, these minimum value data be the minimum value data in n data, form m/2 to adjacent data; Then it compared one by one, the subscript of relatively large number is put into m/2 ~ m-1 unit of c array, this process forms pyramid the 1st layer of tower body;
4., from m-1, compare one by one b [c [m-1]] and b [c [m-2]], b [c [m-3]] and b [c [m-4]] ..., b [c [m/2+1]] and b [c [m/2]], and the subscript of relatively large number is put into c [m/2-1], c [m/2-2] ..., in c [m/4], the rest may be inferred forms pyramid the 2nd, the 3rd ... and even maximum layer tower body, build whole tower body thus, the lower rotating savings of last whole b array maximum value data is placed in c [1];
5. the maximum value data in the b array, 4. obtained for step is composed with minimum value;
6., repeat step 4. with step 5., thus constantly find out the maximal value in b array, and it put into one by one a [0], a [1], a [2] ..., complete sequence.
2. a kind of pyramid sort algorithm according to claim 1, it is characterized in that: described step 1. in the method for searching of integer m be: be 1 to a variable assignments, then the value of this variable and n is compared, if it is less than n, then be multiplied by 2, again compared the value of it and n ... until these data are more than or equal to n, now the value of this variable is m.
3. a kind of pyramid sort algorithm according to claim 1, is characterized in that: described step 3. in adjacent data refer to down that the data that are designated as odd number and the data before it are adjacent data, be not adjacent data with the data after it.
CN201510975288.9A 2015-12-22 2015-12-22 Pyramid sorting algorithm Pending CN105574344A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510975288.9A CN105574344A (en) 2015-12-22 2015-12-22 Pyramid sorting algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510975288.9A CN105574344A (en) 2015-12-22 2015-12-22 Pyramid sorting algorithm

Publications (1)

Publication Number Publication Date
CN105574344A true CN105574344A (en) 2016-05-11

Family

ID=55884470

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510975288.9A Pending CN105574344A (en) 2015-12-22 2015-12-22 Pyramid sorting algorithm

Country Status (1)

Country Link
CN (1) CN105574344A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107015951A (en) * 2017-03-24 2017-08-04 广东顺德中山大学卡内基梅隆大学国际联合研究院 The correctness verification method and system of a kind of Suffix array clustering
CN108616315A (en) * 2018-03-16 2018-10-02 京信通信系统(中国)有限公司 Power amplifier output power detection method, device, computer equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1380606A (en) * 2001-04-11 2002-11-20 陈启星 Method for implementing sequencing and search of hierarchical location by means of calculation
CN1612100A (en) * 2003-10-27 2005-05-04 陈启星 Hierarchical positioning ordering and hierarchical positioning searching dynamic search table algorithm
CN102456073A (en) * 2011-11-03 2012-05-16 中国人民解放军国防科学技术大学 Partial extremum inquiry method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1380606A (en) * 2001-04-11 2002-11-20 陈启星 Method for implementing sequencing and search of hierarchical location by means of calculation
CN1612100A (en) * 2003-10-27 2005-05-04 陈启星 Hierarchical positioning ordering and hierarchical positioning searching dynamic search table algorithm
CN102456073A (en) * 2011-11-03 2012-05-16 中国人民解放军国防科学技术大学 Partial extremum inquiry method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
高飞 等: "《C++与数据结构》", 31 December 2006 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107015951A (en) * 2017-03-24 2017-08-04 广东顺德中山大学卡内基梅隆大学国际联合研究院 The correctness verification method and system of a kind of Suffix array clustering
CN107015951B (en) * 2017-03-24 2020-08-18 广东顺德中山大学卡内基梅隆大学国际联合研究院 Method and system for verifying correctness of suffix array
CN108616315A (en) * 2018-03-16 2018-10-02 京信通信系统(中国)有限公司 Power amplifier output power detection method, device, computer equipment and storage medium
CN108616315B (en) * 2018-03-16 2021-11-02 京信网络系统股份有限公司 Power amplifier output power detection method and device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109886588B (en) Method for solving flexible job shop scheduling based on improved whale algorithm
CN1096524C (en) Steel cord adapted for reinforcement of elastomer
CN104283568B (en) Data compressed encoding method based on part Hoffman tree
CN105574344A (en) Pyramid sorting algorithm
FI3707723T3 (en) Nucleic acid indexing techniques
CO2022010430A2 (en) Method for the treatment of usher syndrome and its composition
CN102704043A (en) Preparation method of polyacrylonitrile pre-oxidation fiber and carbon fiber
US20120163585A1 (en) Masking addition operation device for prevention of side channel attack
CN104809737B (en) Grapefruit image segmentation method based on double-strategy harmony search algorithm
IN2012DN03897A (en)
CN109214088B (en) Rapid layout method for large-scale ultra-sparse planar array with controllable minimum spacing
CN101713000B (en) RT-PCR detection method of ordinary rice black streaked dwarf virus (RBSDV)
CN102665210A (en) Setting method for security key of divisional wireless sensor network
CN102843150B (en) Low-latency QC-LDPC (Quasi-Cyclic Low-Density Parity-Check) parallel encoder and encoding method
CN101783719A (en) Rate matching and rate de-matching method, device and communication system
JP2009524406A5 (en)
CN101941529A (en) Layout method for micro attitude and orbit control thruster array
CN104318307A (en) Tread pattern noise reduction method based on self-adaptive fuzzy genetic algorithm
CN108875301B (en) Gene sequence comparison method, PE configuration controller and readable storage medium
TW200730373A (en) Off-road tire
CN203866647U (en) High-temperature macromolecule leather release paper
CN203866645U (en) Low temperature type macromolecular leather release paper
CN103995821A (en) Selective clustering integration method based on spectral clustering algorithm
CN108449304B (en) Partial transmission sequence method for reducing peak-to-average power ratio of OFDM (orthogonal frequency division multiplexing) signal
CN105450237B (en) A kind of digital intermediate frequency dynamic rage extension method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20160511

WD01 Invention patent application deemed withdrawn after publication