Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default fastest sorting routine for 2-D array of long values

What would be the fastest sorting routine (in VBA or VB) to sort a 2-D array
(2 columns only) of long values?
Maybe it has to be a non-recursive quicksort, but it is not easy at all to
find these.
If somebody has a different way to do this like with a dll that would be
fine as well.
It can't be done in a sheet as there will be more than 65536 rows.
Thanks for any advice.

RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default fastest sorting routine for 2-D array of long values

Disconnected ADO recordset ?
That has a sort method...

Tim

"RB Smissaert" wrote in message ...
What would be the fastest sorting routine (in VBA or VB) to sort a 2-D array (2 columns only) of long values?
Maybe it has to be a non-recursive quicksort, but it is not easy at all to find these.
If somebody has a different way to do this like with a dll that would be fine as well.
It can't be done in a sheet as there will be more than 65536 rows.
Thanks for any advice.

RBS



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default fastest sorting routine for 2-D array of long values

Have tried that one, but it is not the fastest one.
The sorting is very fast, but transferring the array to the
recordset and back spoils it.

RBS

"Tim Williams" <timjwilliams at gmail dot com wrote in message
...
Disconnected ADO recordset ?
That has a sort method...

Tim

"RB Smissaert" wrote in message
...
What would be the fastest sorting routine (in VBA or VB) to sort a 2-D
array (2 columns only) of long values?
Maybe it has to be a non-recursive quicksort, but it is not easy at all
to find these.
If somebody has a different way to do this like with a dll that would be
fine as well.
It can't be done in a sheet as there will be more than 65536 rows.
Thanks for any advice.

RBS




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default fastest sorting routine for 2-D array of long values

Hi RB,

learn more about sorting with Howard Kaikow:

http://www.standards.com/Sorting/Sor...scription.html

And, IMHO, there is no fastest sorting algorithm per se.
There may be a fastest or some equally fast algorithms
for specific data. Some seemably very fast algorithms
won't work at all if the amount of data is too high.



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default fastest sorting routine for 2-D array of long values

Thanks, will have a look.
Typically, I am dealing with arrays like this:

Dim i As Long
Dim arr(0 To 60000, 0 To 1) As Long

Randomize

For i = 0 To 60000
arr(i, 0) = CLng(Rnd() * 60000)
arr(i, 1) = i
Next

RBS


"Helmut Weber" wrote in message
...
Hi RB,

learn more about sorting with Howard Kaikow:

http://www.standards.com/Sorting/Sor...scription.html

And, IMHO, there is no fastest sorting algorithm per se.
There may be a fastest or some equally fast algorithms
for specific data. Some seemably very fast algorithms
won't work at all if the amount of data is too high.



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default fastest sorting routine for 2-D array of long values

Hi "RB Smissaert",

I don't feel qualified to say more than this:

What kind of sorting is fastest
depends on the right assumptions about the data.
In real life, there are rarely data,
which don't have some kind of a structure.

If I look at the screen before me,
and if I had to sort all the pixels by color,
the assumption that after a white pixel
there would come another white pixel,
would be a good guess.
Same with grey pixels, but with a probability
not quite as high as for white pixels.
Very low probability for pink pixels.

If I knew enough about sorting,
I could choose an algorithm optimized
for that situation.

The best algorithm for perfectly randomized data,
where the number of the data is known
and the size of the data as well
depends on the amount of memory you have.
Maybe on the CPU as well.

It's very interesting, but endless.

IMHO

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default fastest sorting routine for 2-D array of long values

This has always been pretty fast for me and allows you to select the column
to sort on and whether ascending or descending.

Sub QuickSort(SortArray, col, L, R, bAscending)
'
'Originally Posted by Jim Rech 10/20/98 Excel.Programming
'Modified to sort on first column of a two dimensional array
'Modified to handle a second dimension greater than 1 (or zero)
'Modified to do Ascending or Descending
Dim i, j, X, Y, mm

i = L
j = R
X = SortArray((L + R) / 2, col)
If bAscending Then
While (i <= j)
While (SortArray(i, col) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j, col) And j L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
Else
While (i <= j)
While (SortArray(i, col) X And i < R)
i = i + 1
Wend
While (X SortArray(j, col) And j L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
End If
If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending)
If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending)
End Sub




Sub aaTesterSort()
Dim bAscending As Boolean
Set rng = Range("I7").CurrentRegion
vArr = rng.Value
bAscending = False
QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending
Range("I26").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr
End Sub

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
Thanks, will have a look.
Typically, I am dealing with arrays like this:

Dim i As Long
Dim arr(0 To 60000, 0 To 1) As Long

Randomize

For i = 0 To 60000
arr(i, 0) = CLng(Rnd() * 60000)
arr(i, 1) = i
Next

RBS


"Helmut Weber" wrote in message
...
Hi RB,

learn more about sorting with Howard Kaikow:


http://www.standards.com/Sorting/Sor...scription.html

And, IMHO, there is no fastest sorting algorithm per se.
There may be a fastest or some equally fast algorithms
for specific data. Some seemably very fast algorithms
won't work at all if the amount of data is too high.



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How fix a too long array function KalleH Excel Worksheet Functions 5 August 24th 09 04:55 PM
Long List of Numbers sorting talltom Excel Worksheet Functions 4 June 11th 07 03:11 PM
Read directly a returned array in the calling routine Jean-Pierre Bidon Excel Programming 4 December 14th 05 01:40 PM
vba routine for sorting an array Taolo Morake Excel Programming 2 August 4th 05 11:20 AM
Adapt an array routine or a better way? Stuart[_5_] Excel Programming 2 July 14th 03 08:35 PM


All times are GMT +1. The time now is 04:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"