Array sorting with heapsort simulating multi-child tree

Asked

Viewed 125 times

2

Doubt:

To order arrays with heapsort, it is customary to simulate in them trees with up to two children per parent, no longer. My question is whether there are studies, implementations, experiments, reports, accessible data that investigate heapsort performance in arrays simulating trees with larger numbers of children per parent.

Details:

I implemented array sorting with heapsort using the maximum of two children per parent. With the notions of code complexity I have, it seemed to me that the number of comparisons of a heapsort interaction (definition of the last element of the current subarray) is, in the worst case, around 2*log2(n), as there are two comparisons per depth level and the depth is around log2(n). But what if I "adopted more children"?

Thinking about it, I suppose we can adapt the code for more than two children by adding, for each additional child, a comparison by depth level. It increases the comparisons by depth, but the depth decreases, thus perhaps making fewer comparisons. The formula I found to estimate comparisons by interaction depending on the number F of children is F*logF(n).

If I’m right, mathematically the ideal would be F = e ~ 2.71828, but you can’t. Increasing from two children to three children would decrease the number of comparisons (-5,36% in F=3). Increase from two to four children, would conserve (0,00% in F=4). Increasing from two to five children or more would increase comparisons (+7,67% if F=5). So, mathematically it is like this, but how is the performance in practice? Has it already been tested? There are known data?

  • 1

    Roughly speaking, the adoption of an extra child would cause asymptotic complexity to be multiplied by a constant term, so it would be within the same time complexity class. Real lead time, though, I don’t know.

  • Exactly. Asymptotically, nothing changes. I want to know how it is in practice. I may have to try it myself. I can’t find anything on the internet.

  • I created a repository in Java to test sorting algorithms, want to include there?

  • Okay, I look. Thank you.

  • https://gitlab.com/totalcross/stack-overflow/tree/master/performance-sort If you can make the ternary heap, it will be a great contribution

  • 1

    Right. I actually implemented it in C++, but I can convert it to java if I can implement it right.

  • 1

    O(log3(n)) and O(log2(n)) are asymptotically equivalent. Which in a way I’m saying what @Jeffersonquesado said but otherwise.

  • Sei... log3(n)=0,63093log2(n)... therefore for n>1 has 0,63092log2(n)<log3(n)<0,63094*log2(n)... logo log3(n)=THETA(log2(n)), etc etc etc. And the practical result of the change in implementation, outside the field of asymptotic analysis?

  • Making the two part of the same temporal class then will only make a difference to a very low N. Which means the gain is not significant for so few operations

  • Even an algorithm 10%, 5%, 3%, even 1% faster is more efficient. Refining it can add more percentages and come up with something really cool. I want to know more about this.

  • @RHERWOLF , something new? Managed to do and get the performance results?

  • I was able to implement it, it has not been wrong... but I could not make the measurements. The differences in results do not cover the measurement errors. I need more precision. I would also like a way to develop arrays in the worst case of heapsort and other algorithms to compare them, even asymptotically insignificant.

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.