(41) Quick Sort
|
03-01-2022, 04:56 AM
Post: #1
|
|||
|
|||
(41) Quick Sort
When using the DM41x, I found that a bubble sort took approximately 1 minute to sort 50 numbers. Since the DM41x is about 50 times as fast as a HP 41C, that means the HP 41C would take approx. 50 minutes to bubble sort 50 numbers.
I implemented a non-recursive version of quick sort based on a public domain algorithm by Darel Rex Finley. In quick sort, there is a begin array pointer (register 95), end array pointer (register 96), left pointer (register 97), right pointer (register 98) and pivot (register 92). There are a few more registers used for loop control, etc. The numbers to be sorted are in registers 0 to 49. I did SIZE 250 just to be safe. The begin array starts at register 120 and the end array starts at register 180. This version took about 31 seconds to sort 50 numbers on the DM41x. Because there’s a lot of overhead in this algorithm, it is only about twice as fast as the bubble sort. To run the quicksort, first do SIZE 250. Store your unsorted numbers in registers 0 to 49. If you want to view the unsorted numbers, you can XEQ VIEWS (and repeatedly press R/S to see each number). Then XEQ QS. You can XEQ VIEWS again to see the sorted numbers. Here is a simple DM41x program to fill the first 50 registers with random numbers using a time based random number generator: LBL "FIL" 0.049 STO 91 LBL "FIL1" TRNG 50 * STO IND 91 ISG 91 GTO "FIL1" RTN Quick Sort Program: Code: LBL "QS" |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(41) Quick Sort - arhtur - 03-01-2022 04:56 AM
RE: (41) Quick Sort - Gene - 03-01-2022, 12:28 PM
RE: (41) Quick Sort - Sylvain Cote - 03-01-2022, 04:08 PM
RE: (41) Quick Sort - Gene - 03-02-2022, 12:24 PM
RE: (41) Quick Sort - Sylvain Cote - 03-02-2022, 02:15 PM
|
User(s) browsing this thread: 3 Guest(s)