home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 5.1 KB | 135 lines | [TEXT/MPS ] |
-
- Sort Library, Version 2.0, Copyright (c) 1990-1994 Ari Halberstadt
-
- Contents:
-
- - Description
- - Portability
- - Notes to users of THINK C
- - Possible Enhancements
- - Your suggestions
- - Known bugs (none)
- - Bibliography
- - My address
-
- DESCRIPTION
-
- This is a free implementation in C of several array sorting algorithms. A
- makefile for UNIX users, an MPW Makefile for the Macintosh, and project
- files for THINK C and CodeWarrior users (also on the Macintosh) are provided.
-
- The purpose of this software is to provide fast and portable implementations of
- the most useful general purpose array sorting algorithms. While for most
- applications quick sort is probably sufficient, having access to the other
- algorithms can be a huge bonus. Never again will you have to sit down to write
- and debug the fastest implementation of some sorting algorithm. Since all the
- functions are designed to be called in the exact same way as the standard
- qsort, it is simple to use the algorithm of your choice. Each implementation
- is guaranteed to return a sorted array [for instance, if merge sort can't
- allocate its auxiliary array, it will call heap sort instead, which still
- gives a time bound of O(n*lg(n))].
-
- The test program provided (in "sort.c") compares several implementations of
- array sorting algorithms. The functions compared are:
-
- qsort The standard library implementation of quick sort.
- qksort My version of quick sort.
- shsort Shell sort.
- hpsort Heap sort.
- mgsort Merge sort.
- insort Insertion sort.
- tqksort Quick sort using integers.
- tshsort Shell sort using integers.
- thpsort Heap sort using integers.
- tmgsort Merge sort using integers.
- tinsort Insertion sort using integers.
-
- Compile and run this program, and then look at the output to see how long it
- takes to sort things using each algorithm. Be prepared to wait a few minutes
- for the results. You may want to adjust the define for MAXDATA in "sort.c" to
- get a value which will not take too long on your machine.
-
- The directory "outputs" contains the program's output for various machines and
- compilers. The directory "source" contains the source code.
-
- PORTABILITY
-
- I tested version 1.0 of this software using gcc on the: NeXT; VAX 11/780
- (UNIX, BSD4.3); and DEC System running Ultrix. I've tested version 2.0 of
- this software on a couple of Unix systems. I also tested version 2.0 on
- the Macintosh using THINK C 7.0 and CodeWarrior DR4. Though a makefile is
- included for MPW, I could not get the MPW C compiler to accept the file
- "sort.c".
-
- The folder "unix" contains files specific to the Unix environment (like the
- Makefile). The folder "macintosh" contains files specific to the Macintosh
- environment (like a project file for users of THINK C).
-
- You should be able to find out if this implementation of qksort is better than
- the version supplied with your compiler, and replace all calls to qsort with
- calls to qksort. For instance, qksort is 4 to 5 times faster than THINK C's
- qsort for random files, and many times faster for presorted files.
-
- POSSIBLE ENHANCEMENTS
-
- I intend to implement the main sorting algorithms for arrays. Each
- implementation will be done in the most efficient manner that I feel like
- doing. Quick sort is just about as efficient as it's likely to get; shell sort
- could use a better increment sequence; heap sort could be further optimized to
- use pointers; merge sort might be convinced to use space n/2 instead of n.
- External and radix sorting functions may be added.
-
- YOUR SUGGESTIONS
-
- If you have any ideas on how to make any of the implementations faster, or
- have specific knowledge of another good sorting algorithm, or have revised the
- programs to be faster, then please let me know. I would like to include these
- enhancements with the next release. Anything you do should, however, be ANSI
- compatible (no assembly language). I will, of course, include proper credits.
- If you compare this software to standard qsort using an as yet untested
- compiler, I'd like to add your test results to the "outputs" file (please
- email me a copy).
-
- Please report any bugs. Please report any potential bugs (eg, overflow,
- underflow, etc). Please report problems executing with ANSI compatible
- compilers.
-
- KNOWN BUGS
-
- Several loops (for instance, for merge sort and shell sort) may cause the
- value of an index variable to exceed the number of items in the array. For
- instance, the following loop:
-
- size_t sz;
- for (sz = 1; sz < n; sz *= 2) { ... }
-
- will stop after sz has reached a value of about 2*n. This could cause an
- overflow problem if n were near the maximum value for type size_t. However,
- since the maximum value of a variable of type size_t is typically at least
- 2^31, I don't see much cause for alarm: no one in the near future is
- likely to sort 2^30 items in memory.
-
- BIBLIOGHRAPHY
-
- Knuth, D. E., "The Art of Computer Programming. Volume 3: Sorting and
- Searching", Addison-Wesley, 1975.
-
- Sedgewick, Robert, "Algorithms", 2nd ed., Addison-Wesley, 1988.
-
- MY ADDRESS
-
- I may be reached, as of November 1994, at the following addresses:
-
- Postal mail:
-
- Ari Halberstadt
- 9 Whittemore Road
- Newton, MA 02158-2105
- USA
-
- Electronic mail:
-
- ari@world.std.com
-
- Electronic mail is preferred.
-