Author Topic: Comparison of sorting algorithms  (Read 3107 times)

0 Members and 1 Guest are viewing this topic.

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11712
  • Country: my
  • reassessing directives...
Re: Comparison of sorting algorithms
« Reply #25 on: July 28, 2022, 06:19:47 am »
For small set of numbers to sort, pc will happily sort with the the new but worst algorithm you put in at 0s.. real life is millions or billions of unsorted numbers. Thats why we came up with some hacks or tricks to deal with since even the best sort will take a while.. such as precomputation and save it somewhere for later use. when inserting value to already sorted values, it only take O(log(n)) instead of dreadful O(n.log (n) ).it looks cute, but not when we are talking billions of numbers.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5144
  • Country: ro
  • .
Re: Comparison of sorting algorithms
« Reply #26 on: July 28, 2022, 07:46:12 am »
It's worth pointing out one more thing ... how much extra memory each algorithm uses.

I could very easily "sort" 1m numbers by making multiple double linked lists   (ex   element.previous - element.value - element.next ) and basically inserting each value as I loop through the million entries into one such list   or by other tricks that use a lot of memory.

For example, let's say the sort key is a 32 bit number ... I could have as many 256 element "buckets" as needed, by using the top 24 bits of the sort key as an id for the bucket.  In each bucket then, you can have up to keys and the positions in the array where these keys show up
When you're done parsing the whole set of numbers, you can just sort the buckets by their id and merge everything in one output array.




 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11712
  • Country: my
  • reassessing directives...
Re: Comparison of sorting algorithms
« Reply #27 on: July 28, 2022, 08:24:47 am »
If you have 2-16GB ram at disposal, you can sort almost any 4bytes length integer with O (n) speed. but thats not the popular way..
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf