📜 ⬆️ ⬇️

ABC sorting


This type of bitwise MSD sort is “sharpened” for strings. However, the algorithm is so named not for lexical specialization. Author Allen Bichik (Allen Beechick) chose a name in honor of himself, ABCsort stands for Allen Beechick Character sort .

Bychik himself is remarkable in that he is not only a programmer, but also a master of theology. The concern of streamlining unsorted data interests him only within the secular profession. Much more respected theologian is concerned with restoring order in the chaos of modern society, on the eve of Ascension for true believers and the Last Judgment for all others.

As for the algorithm, this is the only sort I know, for the use of which its inventor requires money.

')

Bichik



A conservative Baptist, an ardent opponent of preterism . The Protestant heresy was crushed by Allen 30 years ago in his unfading best-selling book “The Ascension on the Eve of the Great Tribulation ” (“The Pre-Tribulation Rapture”, 1980, reprint in 1999). The result of our hero's perennial religious research is the book “ The Ascension Solution - Putting the Puzzle Together ” (“ The Rapture Solution, Putting the Puzzle Together ”).

Benefits


The author likes to praise his algorithm very much and with undisguised pleasure he lists its numerous advantages on the sorting site (web-archive) :



In general, all of the above is true. True, instead of comparisons, exchanges and supporting elements, it was easier to say - this is sorting by distribution. Well, about the "economy of memory" can also be discussed (but more on that later).

What else is good sorting - in contrast to the classic MSD-radix, sort does not sort by all digits. The process stops as soon as the list is sorted, and not until all digits are processed. You can also specify the number of first digits by which ordering will be performed, if seniority by lower digits does not have special significance.

Algorithm


Sorting requires two auxiliary arrays.

One of them is called the word tracker (WT - word tracker), with the help of it we will group words that have the same letters in the i- th digit. For the very first such word found, the value 0 is entered in the list. For each subsequent found word with the same letter in the i- th digit in the word tracker, the index of the previous word corresponding to the same sign is noted.



The following table shows the first stage of sorting, when words are grouped by the first letter. In the process of sorting, when the transition from discharge to discharge occurs, the values ​​in this array change, reflecting chains of words starting with one letter and having the same letters in one place or another.

Another array is a symbol tracker (LT - letter tracker). It marks the indices of the very first (or last) word in the list, in which a certain character is in the corresponding digit. Starting from this word, with the help of the word tracker, the chain of all other lexemes that have the corresponding letter in the i- th digit is restored.


Now the table shows the indices of the last words from the list, which begin with one or another letter.

At this point, using these two tables, you can pull out all the words, for example, starting with the letter “B”. To do this, take the value of the cell LT [1, b] = 9 - this is the index of the last word from the list beginning with “b” - Beckie. This word in the word tracker has a track value now: WT [9] = 8 . This is the index of the previous word on "b" - Belinda. The value 6 is stored in the cell WT [8] - under this index is found Barbara, which in turn indicates the index Beatrix: WT [6] = 3 . The track value for Beatrix is ​​zero, that is, there are no previous words starting with B in the list.

Creating and tracing such chains of words, moving recursively from higher digits to younger ones, as a result, very quickly new sequences are formed, arranged in alphabetical order. Sorting the words into “A”, then “B” is sorted, then “C” and then alphabetically.


C ++ Demo Code (by Lynn D. Yarbrough)
/* ** ABCsort  C **         **   (Allen Beechick)      , **  №5218700. **        . **    : **  .  (Lynn D. Yarbrough) **   (Palm Desert),  **====================================================================== */ #include <malloc.h> #include <stdio.h> #include <stdlib.h> long *RT; /*   */ long **LT; /*   */ void ABCsort (int keys) { /*     */ void process (int, int); long register i, j, recno; int register c; int nodup = noduplicates; long start, step, stop; /*      */ LT = lmatrix(1, keys, alphamin, alphamax); RT = lvector(1, N); /*   : */ for (j = alphamin; j <= alphamax; j++) { for (i = 1; i <= keys; i++) LT[i][j] = 0; } /*    */ if ((keys & 1) ^ nodup) { start = N; stop = 0; step = -1; } else { start = 1; stop = N + 1; step = 1; } /*  1 */ /*      */ for (recno = start; recno != stop; recno += step) { c = GetNextField(recno, 1); RT[recno] = LT[1][c]; LT[1][c] = recno; } /*       . */ process(1, keys); free_lmatrix(LT, 1, keys, alphamin, alphamax); free_lvector(RT, 1, N); } /* ======================================================== */ /*     1- : */ /*  ,       */ void process (int level, int keys) { long i, newlevel, nextrec, recno; int nodup = noduplicates; unsigned char c; /*    */ for (i = alphamin; i <= alphamax; i++) { /*   i-  */ recno = LT[level][i]; LT[level][i] = 0; /*      */ while (recno != 0) { /* i-    ,        */ if (RT[recno] == 0) { PutCurrRecord(recno); recno = 0; continue; } else { /*     i- : */ if (level == keys) { /*      : */ while (recno != 0) { /*       */ PutCurrRecord(recno); recno = RT[recno]; if (nodup) recno = 0; } } else { /*    :*/ /*     */ newlevel = level + 1; while (recno != 0) { nextrec = RT[recno]; c = GetNextField(recno, newlevel); RT[recno] = LT[newlevel][c]; LT[newlevel][c] = recno; recno = nextrec; } /*    */ process(newlevel, keys); } } } } } 


Youtube version of the animation




Time complexity


In general, we can confidently speak of the average time complexity O (k * n) , where k is the number of processed digits.

The company ASIC DESIGN & MARKETING , which is engaged in the development of integrated circuits, implemented the algorithm when creating an FPGA ( User-programmable gate arrays ). According to the company's engineers, ABCsort works 2.5 to 10 times faster than QuickSort . You can read about this in this PDF report .

Memory difficulty


Two auxiliary arrays will be required for sorting: two-dimensional for the character tracker, which can be neglected when estimating complexity. As well as an array of n elements for the word tracker. That is, the total estimate of additional memory: O (n) .



Price


If you liked the algorithm, then do not rush to run it in production, without paying the owner compensation. The method is patented ( link to the pdf of the patent ) and for its pirated use a punishing sword of American justice will fall on the thief.

The price for sorting is quite divine, $ 49. For this amount, a satisfied customer receives:



If to throw over 39 conventional units, then DLL-ku will be given with commented source codes in C ++.

An enterprising religious scholar and programmer swears by all the saints that if ABC sort does not turn out to be at least twice as fast as Quick sort , then he will unconditionally return the money.

Those who have questions about the patent, Allen Bichik gives exhaustive answers:
Maybe you should sell the Microsoft algorithm?

I've tried. That was before I received the patent. The guys from “Microsoft” said they would not be able to patent, because this is another kind of bitwise sorting; besides, she was not impressed. But the patent office saw the uniqueness of the algorithm.

Why don't you pass the algorithm into the public domain?

A patent attorney does not work for nothing. Government service does not issue patents for free. So, it is not bad to return at least a part of the money spent out of one’s own pocket.


Algorithm Characteristics


TitleABC sorting (ABCsort, Allen Beechick Character sort);
Beechick sort
AuthorAllen Beechick
Year of publication1993
ClassSort by distribution
SubclassBitwise sorting
ResilienceSteady
ComparisonsNo comparisons
Time complexitythe worstaveragethe best
O (k * n)O (k * n)O (n)
Memory difficultyO (n)


Links


Sorting site (web archive)
Lina D. Yarbrough implementation in C ++ (web-archive)
Algorithm Patent (pdf)
Hardware implementation in integrated circuits (pdf)

Allen Beachick


On Facebook
On LinkedIn
The site of the book “The solution of Ascension - let's put the puzzle together”


Voting

Source: https://habr.com/ru/post/201534/


All Articles