Mouse teaches us that we can append additional information to a numeric key to create a new larger number.
We do this by shifting the key as many bits to the left as the tied information has. In the obtained place we insert the
related information.
This additional information could be a pointer to related data. This pointer may be an index instead of an address.
The above solution has become more possible in today's 64-bit era. 32 bits used to have fewer opportunities to pack
essential information into our numerical mini-records.
And this idea has a great future ahead of it. Have you heard about AVX-512 and 512 bit ZMM0-31 registers?
Due to the difficulty of answering, this question quickly turns into
another question: why to sort an array of numbers at all?
MichaĆ Kasprzak <siarc...@gmail.com> writes:
Due to the difficulty of answering, this question quickly turns into another question: why to sort an array of numbers at all?One obvious reason is to check the array for duplicates. The C++ code
that I posted for the taxicab problem did that. Another might be to
find the median. Sorting is a convenient though not optimal way to do
that. Or, you might want to know what the largest or smallest N numbers
are. Again, sorting is a straightforward method.
Finding duplicates and largest/smaller need only a single pass through
all elements.
The median can be done in O(n) in a few lines?
Marcel Hendrix <mhx@iae.nl> writes:
Finding duplicates and largest/smaller need only a single pass through
all elements.
Finding duplicates in a single pass needs some kind of lookup table,
right? So there is more storage overhead than just sorting in place.
Similarly, the "right" way to find the N largest (say N=100) is to use a
heap as a priority queue and pull off N elements,
The median can be done in O(n) in a few lines?
I wasn't aware of that and I thought it was more complicated. I know of
a guaranteed O(n) method that is fairly intricate, and an O(n)
average-case method that amounts to doing quicksort but figuring out
after each pivot which partition contains the median and only recursing
on that partition instead of on both.
Again though, sorting takes 1
line instead of "a few".
This additional information could be a pointer to related data.
This pointer may be an index instead of an address.
We can now use our very quick heapsort word.
In article <4bba2005-0bb4-46b4-9535-0dbff5d6348en@googlegroups.com>,
Micha? Kasprzak <siarczek83@gmail.com> wrote: <SNIP>
This additional information could be a pointer to related data.
This pointer may be an index instead of an address. We can now use
our very quick heapsort word.
An important note is that pointers have a detrimental effect on the
locality of memory access (caching issues). I'd say that quicksort
using pointers is about as efficient as heapsort without pointers.
Groetjes Albert
On 23.08.2022 12:30, albert wrote:...
In article <4bba2005-0bb4-46b4-9535-0dbff5d6348en@googlegroups.com>,
Micha? Kasprzak <siarczek83@gmail.com> wrote: <SNIP>
This additional information could be a pointer to related data.
This pointer may be an index instead of an address. We can now use
our very quick heapsort word.
An important note is that pointers have a detrimental effect on the
locality of memory access (caching issues). I'd say that quicksort
using pointers is about as efficient as heapsort without pointers.
That's firstly a question of the locality of the pointed-to data. If
they are organized in an array, and you have another array of pointers
into that array, the data to be sorted will be cached alike.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:08:22 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,091 |