(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" |
|||
03-01-2022, 12:28 PM
Post: #2
|
|||
|
|||
RE: (41) Quick Sort
I'd like to see what the PPC ROM routines S2 and S3 do with large data sets on the DM41X.
|
|||
03-01-2022, 04:08 PM
(This post was last modified: 03-02-2022 02:37 AM by Sylvain Cote.)
Post: #3
|
|||
|
|||
RE: (41) Quick Sort
(03-01-2022 12:28 PM)Gene Wrote: I'd like to see what the PPC ROM routines S2 and S3 do with large data sets on the DM41X. DM41X Results (DMCP 3.2 & DM41X 2.1) Code: R= 25 // Power:USB // S2= 0s 66 // S3= 0s 71 41CL Results (latest update) Code: R= 25 // Turbo:x50 // S2= 2s 12 // S3= 2s 18 Test Code: CLRG Data Loader → Y=random-generator-seed X=Registers SSS.EEEII Code: LBL "DTALD" Code: LBL 10 Code: LBL "DTAS2" Code: LBL "DTAS3" |
|||
03-02-2022, 12:24 PM
Post: #4
|
|||
|
|||
RE: (41) Quick Sort
Wow, S2 and S3 are incredibly fast !
ty Sylvain. Gene |
|||
03-02-2022, 02:15 PM
Post: #5
|
|||
|
|||
RE: (41) Quick Sort | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)