On modern hardware the min-max heap beats a binary heap
probablydance.com
On modern hardware the min-max heap beats a binary heap
1–10 of 44 posts
Re: On modern hardware the min-max heap beats a binary heap
#2So, it's nice to see a detailed analysis of the structure like this! Perhaps if it becomes more popular, I will find more places to use it.
Re: On modern hardware the min-max heap beats a binary heap
#3Very useful when you need it!
Re: On modern hardware the min-max heap beats a binary heap
#4Re: On modern hardware the min-max heap beats a binary heap
#5So in that case I would use this data structure even if it weren't faster. I can't count the number of times I have had to mess with inserting negative priorities into a min heap to create a max heap! We should just have one data structure that does both.
(though taking this idea to the logical extreme means we should just use Order Statistic Tree for everything since it not only gives you log(n) min/max, but also log(n) find kth and get rank of x)
Re: On modern hardware the min-max heap beats a binary heap
#6In certain domains, the trend has been to give up constant factors in order to increase programmer productivity (e.g., python pays a 10x slowdown but is batteries included). So in that case I would use this data structure even if it weren't faster. I can't count the number of times I have had to mess with inserting negative priorities into a min heap to create a max heap! We should just have one data structure that d…
Re: On modern hardware the min-max heap beats a binary heap
#7Impressive. Looking forward to the d-heap article.
https://en.wikipedia.org/wiki/D-ary_heap
(Also I didn't know they were called d-heaps, thanks!)
Re: On modern hardware the min-max heap beats a binary heap
#8Re: On modern hardware the min-max heap beats a binary heap
#9(Like how linear search wins for small N, or insertion sort helps with small subarrays in introsort: more steps, but each step is also a lot cheaper on modern hardware due to fewer branch mispredictions, better cache locality, or something else that better fits the hardware's strengths.)
Re: On modern hardware the min-max heap beats a binary heap
#10In certain domains, the trend has been to give up constant factors in order to increase programmer productivity (e.g., python pays a 10x slowdown but is batteries included). So in that case I would use this data structure even if it weren't faster. I can't count the number of times I have had to mess with inserting negative priorities into a min heap to create a max heap! We should just have one data structure that d…
Surely you should ve able to just use a different comparator instead (> instead of <).
The real problem is if you need min/max at the same time. Then you not only need a min heap and max heap, you also need to track what was already popped from either heap! This is because in python you can't delete an element if it's not at the root. So tracking "tombstones" will let you pop from one heap, then know to ignore it the next time it comes up in the other heap.
This is of course super complicated to maintain and I get it wrong all the time. Luckily only shows up in algo interview problems.