QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

Comparison of the Five Sorting Methods

September 26 2002 at 12:47 PM
  (Premier Login iorr5t)
Forum Owner


Response to Five (5) sorts comparison program

 

Five sorts are provided in the post above:
1=Solitaire
2=Selection
3=Bubble
4=Shell
5=QuickSort

1=Solitaire
This is the sort that Solitaire published and named the "Shell" sort. I don't think it is, but there are conflicting definitions on the web.

Looking at
http://www.scifaiku.com/tom/programs/sorts.html
it seems like this matches QuickSort more than Shell.

Anyway, I tried it on 10,000 numbers and it ran in 18 seconds.

2=Selection
This is the sort that has been called the "Bubble" sort many times in the QBasic forum. I believe that "Selection" is the correct name.
Anyway, I tried it on 10,000 numbers and it ran in 518 seconds.

3=Bubble
This is the correct "Bubble" sort. I didn't try it because it is always even worse than the Selection sort.

4=Shell
This is the correct "Shell" sort (I think).
Anyway, I tried it on 10,000 numbers and it ran in 24 seconds.

5=QuickSort
This is the correct version, I think.

Sorting an array of 10000 elements
==================================
S = Results when sorting an already Sorted file
U = Results when sorting an unsorted (random) file

  S      U    Sort Used
----- ------  ---------
0.16   1.92  Solitaire
56.08  77.88  Selection
0.00 249.09  Bubble
3.71  22.01  Shell
0.17   0.33  QuickSort

Conclusion: For large tables, the QuickSort is best and even if the table is previously sorted, you don't loose much time.

For short tables (less that 100 elements) I would use the Selection sort, as it is easiest to code.

Mac


    
This message has been edited by iorr5t on Nov 10, 2003 11:15 AM


 
 Respond to this message   
Responses

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums