NOTICE: This article originally appeared in the October, '88 issue of Michigan Atari Magazine and may be freely distributed or reprinted in non-profit User Group publications as long as the article's author and Michigan Atari Magazine are credited AND this notice is reprinted with the article. All other publications must obtain written permission from Unicorn Publications, 3487 Braeburn Circle, Ann Arbor, MI 48108, Phone: (313) 973-8825 before using this article. The Sport of Sorts by Clinton Pierce (GAG) In this installment we're going to look at one of the most fundamental problems in computers, sorting. Human beings, as a rule, have an amazing sense of geometric perception. They will sort index cards with names on them by placing the names in relative order on the table (A is a lot farther away from P, than M is), and doing fine adjustments as they go along. Computers aren't human. They must sort using absolutes. You must tell them what is to be sorted (records), how it is to be sorted (keys), and where it is to go to (output). And they can only compare (again, as a rule) two things at a time. The first sort is the standard Hey-I-learned-that-in-BASIC sort: the bubble sort. The bubble sort compares two elements in an array, and if they are in the wrong order, swiches them around. It is finished when either n^2 repetitions have occured, or when no more switches are made in an entire pass. The next sort is Shell's sort (named after a man, not the method). A Pseudo-BASIC program follows for an array a, N elements long: 1.M=N 2.M= Intger part of M/2, If m=0 then the sort is done else: J=1, K=N-M 3. I=J 4. L=I+M, If a(i) a(x) down one element, make z(q)=a(x), Increase X and Q. #3 Go to step 2 until q=N. This sort is moderately fast. Next, Quicksort, is the fastest sort I've dealt with. A complete algorythm will not be given until the unit on Recursion. But here's how it works: Given an array 1..N, arrange the array so that all values < a pivot value, are first, and > pivot are last. Then, the pivot is in its proper place. It is then done again, and again, using each smaller region until the array is sorted. The sort is incredibly fast. The number of passes needed is only N times the Base-2 log of N. (Where bubblesort would use 4096 repetitions, quicksort uses 384). Until next time....Hasta Luego.