home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / NextDeveloper / Examples / AppKit / SortingInAction / English.lproj / HelpPanel.nib / data.nib (.txt) < prev    next >
Encoding:
NeXT TypedStream Data  |  1992-06-16  |  10.0 KB  |  106 lines

  1. typedstream
  2. IBObjectData
  3. Object
  4. CustomObject
  5. SortApp
  6. WindowTemplate
  7. iiii***@s@
  8. Panel
  9.     Responder
  10. Helvetica-Bold
  11. Button
  12. Control
  13. ButtonCell
  14. ActionCell
  15.     Helvetica
  16. NXImage
  17. ScrollView
  18. ClipView
  19. ciifffcfffs
  20. [8944c]{\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fswiss Helvetica;}
  21. \margl40
  22. \margr40
  23. {\colortbl;\red0\green0\blue0;}
  24. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\f0\b0\i0\ulnone\fs28\fc0\cf0 \
  25. \f1\b Sorting in Action!
  26. \f0\b0  is an educational tool to help you learn about sorting algorithms.  There are many neat ways to go about sorting a data set, and this little program illustrates six of the standard algorithms.  Each sort is graphically animated, so you can watch it in progress.  Capitalizing on the magic of Mach threads, the program can run the sorts against one another in parallel to show you a reasonably fair comparison of the efficiency of the sorts.  By adjusting the sort parameters, you can explore how the efficiency of each algorithm is related to the size and type of data set used.  Intrigued already?  Read on.\
  27.     The 
  28. \b Sort Parameters
  29. \b0  panel has the controls to set up a sort.  The 
  30. \b Data Set
  31. \b0  box allows you to specify the size of the data set and what percentage of the data is already in sorted order.  If you ask for 0% percent sorted data, all elements of the data set will be randomly generated.  A 42% sorted data set would have 58% random elements inserted into 42% pre-sorted data.  A 100% sorted set is all already in sorted order - try it out and find out which sorts are smart enough to take advantage of data already sorted and which ones aren't!  \
  32.     The 
  33. \b Algorithms
  34. \b0  list indicates which sorts you would like to run.  Simply check the boxes for the sorts you want to see.  The descriptions of the different algorithms are below.\
  35.     You also have the choice of running the sorts in 
  36. \b Parallel
  37. \b0  or in 
  38. \b Series
  39. \b0 .  In series you can watch each algorithm individually, while in parallel you can watch the sorts compete.\
  40.     By changing the 
  41. \b Value of Sorting Operations
  42. \b0 , you adjust the "tick" cost charged to a sort for the basic operations.  You can explore how the sorts perform differently with various weights assigned to the operations.  For example, if you were sorting a data set of large records by an integer field, compares would be cheap and moves would be expensive. (Selection sort excels in this situation).  Changing the tick costs can also simulate the effects of changing the hardware or the implementation language.\
  43.     When you have configured the sort to your preferences, click on the "
  44. \b Go!
  45. \b0 " button to make it all happen.  Once the sort has begun, the Go button changes to the "
  46. \b Stop
  47. \b0 " button which you can use to cancel the sorts in progress. \
  48.     The algorithms will animate their progress as they sort.  The 
  49. \b Animate Compares
  50. \b0  switch controls whether the sorts will also highlight in gray the two elements being compared.  This provides feedback on the comparisons the algorithms are making.  The 
  51. \b Animation Speed Slider
  52. \b0  allows you to slow the progress of the sort.  You can follow the sorts more carefully in slow motion. \
  53.     When a sort finishes, it will fade out and display its running time statistics.  The statistics indicate how many compares, moves, and function calls the algorithm used to sort the data, as well as its final tick count.\
  54. \f1\fs48 The Algorithms
  55. \f0\fs28 \
  56. \b Bubble Sort
  57. \b0 \
  58. A classic sort, although not a particularly efficient one. 
  59. \fc1\cf1  
  60. \pard\fc0\cf0 Its basic strategy is to begin at top and look at the first two elements and move the larger of the two down.  Then it looks at the the second and third elements, moves the larger down.   It continues like this, "bubbling" the largest element down to the very bottom. Then it returns to the top to do it all over again.  It finishes when no more elements need to be exchanged.  
  61. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0\cf0 It is the poorest performer of the O(n^2) sorts, although it does improve somewhat on partially sorted data.  As Don Knuth said, "
  62. \fc1\cf1 In short, the bubble sort seems to have nothing to recommend it, except a catchy name and the fact that it lead to some interesting theoretical problems."  If you are ever tempted to use Bubble Sort, wait for the feeling to pass, and then use Insertion Sort which is marginally faster and easier to write.\
  63. \b Insertion Sort
  64. \b0 \
  65. An intuitive sort, if not a fast one.  It incrementally builds a sorted list by considering each element in turn and inserting it in its proper place among those already sorted.  In the beginning, the first element constitutes the sorted list.  Then, inserting second element before or after the first element creates a sorted list length two.  Subsequent elements are inserted into the growing list.  Each insertion becomes more costly as the sorted list gets longer since it takes longer to find the proper place--notice how insertion sort slows down as it gets to the final elements.  It is an O(n^2) sort, but works well on small data sets and takes advantage of partially sorted data. \
  66. \b Merge Sort
  67. \b0 \
  68. A fairly fast and extremely stable recursive algorithm.  It divides the data set into two equal halves, recursively sorts those two halves, and then merges the results together.  It is very consistent - if makes no difference if the data is sorted or not.  Merge Sort is always O(nlogn).  As a side note, this sort uses more memory than my other sorts because I create a new array to hold the sorted and merged array.  I once heard there was an algorithm to merge the two within the same array, but I couldn't figure that one out.\
  69. \b Quicksort
  70. \b0 \
  71. True to its name, this sort is fast, but it is not without its faults.   It works by partitioning a data set into two parts and then recursively sorting the parts.  It divides the data by choosing a pivot value and moving all elements less than the pivot into one partition, all elements greater than the pivot go to the other.  Each of the partitions are split again with a new pivot, and following the magic trail of recursion it arrives at a sorted data set.  It is fast, even with the overhead of recursion.  However, with a poor pivot choice, it can slow down enormously.  A poor pivot choice is one that divides the data lopsidedly instead of creating two fairly equal partitions.  For this reason, Quicksort works particularly poorly on data that is already sorted.  Already sorted data is, in fact, its worst case at O(n^2) whereas its average case is O(nlogn).\
  72. \b Selection Sort
  73. \b0 \
  74. Selection sort is not terribly fast, but the algorithm is the easiest to understand. It searchs the data set for the smallest element, and puts it in the first position.  Then it seeks out the next smallest element to put in the second position and so forth.  Lots and lots of comparision, but very little moving. Another of the O(n^2) variety sorts.  As this algorithm is quite stable, it doesn't perform any better or worse on sorted data.\
  75. \b Shellsort
  76. \b0 \
  77. Shellsort is a variation on Insertion Sort that is virtually unbeatable on small data sets.  Insertion Sort is slow because it only exchanges adjacent elements.  Shellsort circumvents this by allowing the exchange of elements that are farther apart.  It works by first performing Insertion Sort on subsets of the data.  For example, Shellsort might first sort the set of elements 1, 6, 11, 16... relative to each other--the effect is that the elements in that subset are moved much closer to their final positions.  At first the sets are wide-spread, perhaps every fortieth element.  Then it repeats using a tighter set, perhaps every fourteenth element, then every fourth element.  Each of these passes is much cheaper than a traditional Insertion Sort pass.  The effect of the passes is that the data set is mutated to be in "almost sorted" order.  The final insertion sort pass can then go very quickly because insertion sort does very well on almost sorted data.  In other words, at first the elements take large leaps to the general location they belong and successively smaller steps move the element to its precise place. I call this algorithm "inscrutable sort" because even after having coded the algorithm, I still have trouble following the animation.  No one has been able to analyze this algorithm rigorously; the functional form of the running time is conjectured to be O(N^1.25).  Shellsort may be a bit mysterious, but it is an good general purpose sort since it has excellent performance and the code you must write is only slightly more complex than Insertion Sort.\
  78. Well, that about does it.  \
  79. \b Many thanks for help and inspiration from
  80. \b0 :        \
  81. Paul Hegarty & Trey Matteson (programmers extraordinaire)\
  82. Joe Liemandt & Lance Nakata (cube provisions)\
  83. Nick Parlante (enthusiasm, of course!)\
  84. \i Sorting Out Sorting 
  85. \i0 - the movie (from University of Toronto)\
  86. \i Algorithms
  87. \i0  Robert Sedgewick\
  88. \i Sorting and Searching
  89. \i0  Donald Knuth\
  90. and an entire dorm of beta-testing frosh! jz      
  91. NXCursor
  92. NXibeam
  93. Scroller
  94. _doScroller:
  95. @@@ffs
  96.     TextField
  97. TextFieldCell
  98. Sorting in Action!
  99.     HelpPanel
  100. Field2
  101. File's Owner
  102. ScrollingText
  103. IBOutletConnector
  104. IBConnector
  105.     helpPanel
  106.