Quick sorting method based on two-dimensional hash table

Through a quick sorting method based on a two-dimensional hash table, using hash operation and address writing table, the problem of high complexity in traditional sorting algorithms in embedded devices is solved, and the fast sorting with low complexity and low resource occupation is achieved. Suitable for practical applications of embedded devices.

CN119248972APending Publication Date: 2025-01-03CNGC COMM TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411773779.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

Traditional sorting algorithms have problems in embedded devices with high algorithm complexity and lack of real-time requirements. Especially when dealing with pseudo-random sequences, a method that can be quickly and efficiently sorted is needed.

Method used

A quick sorting method based on a two-dimensional hash table is adopted, by constructing a two-dimensional hash table and a write address table, storing and reading subscripts are used to realize sorting, and using a two-way circular linked list to optimize memory usage when necessary.

Benefits of technology

It effectively reduces the time complexity and spatial complexity of sorting, and is suitable for embedded devices. It has the advantages of low algorithm complexity and low hardware resource utilization, and is suitable for practical engineering applications in the embedded field.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248972A_ABST
    Figure CN119248972A_ABST
Patent Text Reader

Abstract

The invention provides a quick sorting method based on a two-dimensional hash table, which comprises the following steps of: constructing the two-dimensional hash table H [M] [N] and a subscript sequence number table Xi [N] of a number sequence X according to the length N of elements in the repeatable positive integer number sequence X and the maximum value M in the elements; the subscripts in the subscript sequence number table Xi [N] are sequentially stored in a two-dimensional hash table H [M] [N], and the subscripts are stored in rows corresponding to corresponding elements of the subscripts and start to be stored from the left; sequentially reading subscripts in the hash table H [M] [N] from left to right and from top to bottom, and storing the read subscripts in an ordered subscript sequence number table Yi according to a reading sequence; according to the ordered subscript sequence number table Yi, obtaining a sorted ordered sequence Y from the positive integer sequence X through a table look-up method; and for the repeatable sequence with limited length and range, the two-dimensional hash table is used for quick sorting, so that the sorting calculation time can be effectively shortened, and the time complexity is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of data processing, and in particular to a quick sorting method based on a two-dimensional hash table. Background Art

[0002] The sorting algorithm of digital sequences is an algorithm widely used in the fields of information processing, artificial intelligence, and communications. Traditional sorting algorithms such as bubble sort, selection sort, and shell sort have problems such as high algorithm complexity and disorder of the same value. In the field of communications, pseudo-random number sequences are often used for encryption operations, which require repeated numerical sequences to be sorted and arranged in order of subscripts. At the same time, the computing power of embedded devices is limited, and they have higher requirements for the complexity and real-time performance of the sorting algorithm of digital sequences. Therefore, it is of great practical significance to design a fast sorting algorithm suitable for engineering applications in the embedded field. Summary of the invention

[0003] In view of the needs in the prior art, the present invention provides a quick sorting method based on a two-dimensional hash table, the purpose of which is to reduce the time complexity of the algorithm and the amount of calculation.

[0004] A quick sorting method based on a two-dimensional hash table comprises the following steps: Step 1: According to the length N of the elements in the positive integer sequence X and the maximum value M of the elements, construct a two-dimensional hash table H[M][N] and a subscript number table Xi[N] of the sequence X. The positive integer sequence X has repeated elements. Step 2: Store the subscripts in the subscript sequence table Xi[N] in sequence in the two-dimensional hash table H[M][N], where the subscripts are stored in the rows corresponding to their corresponding elements and are stored from the left; Step 3: Read the subscripts in the two-dimensional hash table H[M][N] from left to right and from top to bottom, and store the read subscripts in the ordered subscript number table Yi in the reading order; Step 4: According to the ordered subscript number table Yi, obtain the sorted ordered sequence Y from the positive integer sequence X by table lookup method.

[0005] Further: Step 2 includes the following steps: Step 2.1: Construct a write address table D[M], and set the initial values ​​of the write address table D[M] to 0; Step 2.2: Perform a hash operation on the elements in the positive integer sequence X to obtain the row number i; Step 2.3: Look up the write address table D[M] to get the column number j=D(i), and increment the value of D(i) by 1, i∈[0,M), j∈[0,N); Step 2.4: According to the row and column numbers (i, j), store the subscripts in the two-dimensional hash table H[M][N]; Step 2.5: Repeat steps 2.2 to 2.4, traverse the positive integer sequence X from left to right, and store the subscripts corresponding to the elements in the corresponding positions in the two-dimensional hash table H[M][N].

[0006] Further: In the two-dimensional hash table H[M][N], a bidirectional circular linked list is used instead of a horizontal array, and the corresponding subscript is linked to the corresponding linked list head.

[0007] The beneficial effects of the present invention are as follows: for repeatable number series with limited length and range, fast sorting using a two-dimensional hash table can effectively reduce the sorting calculation time and reduce the time complexity. The method has the advantages of low algorithm complexity and less hardware resource occupation, and has high reference and use value in practical engineering applications in the embedded field. BRIEF DESCRIPTION OF THE DRAWINGS

[0008] Figure 1 It is a sorting flow chart of the present invention; Figure 2 It is a schematic diagram of storing subscript numbers of the present invention; Figure 3 It is a schematic diagram of reading the subscript number of the present invention; Figure 4 It is a comparison chart of the sequence sorting of the present invention; Figure 5 This is a schematic diagram of the hash chain sorting of the present invention. DETAILED DESCRIPTION

[0009] The present invention is described in detail below in conjunction with the accompanying drawings. The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be interpreted as limiting the present invention. The directional terms such as left, middle, right, top, and bottom in the embodiments of the present invention are only relative concepts or are based on the normal use state of the product, and should not be considered as restrictive.

[0010] A quick sorting method based on a two-dimensional hash table, such as Figure 1 As shown, the following steps are included: Step 1: According to the length N of the elements in the positive integer sequence X and the maximum value M of the elements, construct a two-dimensional hash table H[M][N] and a subscript number table Xi[N] of the sequence X, so that each element in the positive integer sequence X has a corresponding row in the two-dimensional hash table H[M][N], the number of columns in the two-dimensional hash table H[M][N] is N+1, and the positive integer sequence X has repeated elements; a very important feature of the present invention is that it is applied to sorting sequences with repeatable elements, because the two-dimensional hash table H[M][N] designed for repeated numbers puts repeated numbers in one row, and in the extreme case all are repeated, so the designed row length is N, so in the present invention, the positive integer sequence X is a repeatable sequence, and the subscripts are ordered after sorting; For example: the positive integer sequence [5,8,8,5,7,6,1,7,5,2,10,······,255,9] with a sequence length of 164 and a value range of 0~255, and the maximum value is 255, then: X

[164] =[5,8,8,5,7,6,1,7,5,2,10,······,255,9]; Number list; Xi

[164] =[1,2,3,4,5,6,7,8,9,10,11,······,163,164]; Subscript number table; H

[256]

[164] ={0}; two-dimensional hash table; D

[256] = {0}; write address table; Y

[164] = {0}; ordered list; Yi

[164] = {0}; ordered subscript number table; Step 2: If Figure 2 As shown, the subscripts in the subscript sequence table Xi[N] are stored in sequence in the two-dimensional hash table H[M][N], wherein the subscripts are stored in the rows corresponding to their corresponding elements and are stored from the left; To facilitate the storage of the subscript in the two-dimensional hash table H[M][N], step 2 includes the following steps: Step 2.1: Construct a write address table D[M], and set the initial values ​​of the write address table D[M] to 0; Step 2.2: Perform a hash operation on the elements in the positive integer sequence X to obtain the row number i. For example, the first element x=5 of the positive integer sequence X is hashed (5 modulo 255) to obtain the row number i=5. Step 2.3: Look up the write address table D[M] to get the column number j=D(i), and increment the value of D(i) by 1, i∈[0,M), j∈[0,N); for example: row number i=5, look up the write address table to get the column number j = D(5)=0 (initialized value), then increment the write address by 1 to get D(5)=1 (update the initialized value); Step 2.4: Store the subscript in the two-dimensional hash table H[M][N] according to the row and column numbers (i, j); for example, store the subscript of the first element (Xi(1)=1) in the two-dimensional hash table H(5,0); Step 2.5: Repeat steps 2.2 to 2.4, traverse the positive integer sequence X from left to right, and store the subscripts corresponding to the elements in the corresponding positions in the two-dimensional hash table H[M][N]; Step 3: Read the subscripts in the two-dimensional hash table H[M][N] from left to right and from top to bottom, and store the read subscripts in the ordered subscript number table Yi in the order of reading; for example: the first subscript H(1,0) is 7, the second subscript H(2,0) is 10, and finally the ordered subscript sequence Yi

[164] =[7,10,1,4,9,6,5,8,2,3,164,11,······,163] is obtained, as shown in Figure 3 As shown; Step 4: According to the ordered subscript number table Yi, use the table lookup method to obtain the sorted ordered number sequence Y from the positive integer sequence X; for example: the first element of the ordered subscript number table Yi is 7, and X(7)=1, so Y(1)=1, and so on, we get the ordered number list Y

[164] =[1,2,5,5,5,6,7,7,8,8,9,10, ·····,255], such as Figure 4 shown.

[0011] In addition, in other embodiments, in order to solve the problem that the space complexity of the two-dimensional hash table sorting algorithm is high and the algorithm implementation occupies a large amount of memory when the length of the sequence is large, a two-dimensional hash table H[M][N] uses a bidirectional circular linked list instead of a horizontal array, and links the corresponding subscript to the corresponding linked list head, and the bidirectional circular linked list needs to be initialized; the basic sorting idea is similar to the above steps, firstly, the linked list array is initialized, and then the corresponding subscript is linked to the corresponding linked list head according to the hash operation result, and then the subscript is read from left to right and from top to bottom, and finally the address mapping obtains a sequence of numbers with the same value in order from small to large, such as Figure 5 As shown in the figure, after optimizing the bidirectional circular linked list, the memory occupancy rate can be effectively reduced and the space complexity can be reduced at the expense of a certain time complexity.

[0012] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A quick sorting method based on a two-dimensional hash table, characterized in that: The following steps are involved: Step 1: According to the length N of the elements in the positive integer sequence X and the maximum value M of the elements, construct a two-dimensional hash table H[M][N] and a subscript number table Xi[N] of the sequence X. The positive integer sequence X has repeated elements. Step 2: Store the subscripts in the subscript sequence table Xi[N] in sequence in the two-dimensional hash table H[M][N], where the subscripts are stored in the rows corresponding to their corresponding elements and are stored from the left; Step 3: Read the subscripts in the two-dimensional hash table H[M][N] from left to right and from top to bottom, and store the read subscripts in the ordered subscript number table Yi in the reading order; Step 4: According to the ordered subscript number table Yi, obtain the sorted ordered sequence Y from the positive integer sequence X by table lookup method.

2. The fast sorting method based on a two-dimensional hash table according to claim 1, characterized in that: Step 2 includes the following steps: Step 2.1: Construct a write address table D[M], and set the initial values ​​of the write address table D[M] to 0; Step 2.2: Perform a hash operation on the elements in the positive integer sequence X to obtain the row number i; Step 2.3: Look up the write address table D[M] to get the column number j=D(i), and increment the value of D(i) by 1, i∈[0,M), j∈[0,N); Step 2.4: According to the row and column numbers (i, j), store the subscripts in the two-dimensional hash table H[M][N]; Step 2.5: Repeat steps 2.2 to 2.4, traverse the positive integer sequence X from left to right, and store the subscripts corresponding to the elements in the corresponding positions in the two-dimensional hash table H[M][N].

3. The fast sorting method based on a two-dimensional hash table according to claim 1, characterized in that: In the two-dimensional hash table H[M][N], a bidirectional circular linked list is used instead of a horizontal array to link the corresponding subscript to the corresponding linked list head.