VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Optimized QuickSorts

by Roger Gilchrist (50 Submissions)
Category: Coding Standards
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

QuickSort is one of the fastest sorts available but contains a couple of gotcha's. You cannot just stick any old QuickSort into your code; you have to optimize it to the data you are sorting.
--------------------------------
This demo provides optimized versions for each of the major variable types (Integer and Byte are not covered but you should be able to work it out). It also demonstrates some of the problems with using the wrong QuickSort and demonstrates the sheer speed of QuickSort on different data types.
--------------------------------
The other Gotcha is that if the data is nearly sorted then it can be very slow. But all of these QuickSorts also have a an asending/desending switch, if you suspect your data is near sorted then reverse it first.
--------------------------------
A further optimization is that if you only need one direction in your code you can strip out the asending/desending switch improving speed greatly because you are not passing a parameter.
--------------------------------
If you want both you could also use a Variable to control the direction instead of the parameter.

Rate Optimized QuickSorts

Download Optimized QuickSorts

Download Optimized QuickSorts (6 KB)

Optimized QuickSorts Comments

No comments have been posted about Optimized QuickSorts. Why not be the first to post a comment about Optimized QuickSorts.

Post your comment

Subject:
Message:
0/1000 characters