Can max/min heap trees contain duplicate values?

Yes, they can. You can read about this in ‘Introduction to Algorithms’ (by Charles E. Leiserson, Clifford Stein, Thomas H. Cormen, and Ronald Rivest). According to the definition of binary heaps in Wikipedia: All nodes are either [greater than or equal to](max heaps) or [less than or equal to](min heaps) each of its children, according … Read more

Efficient heaps in purely functional languages

There are a number of Haskell heap implementations in an appendix to Okasaki’s Purely Functional Data Structures (pdf). (The source code can be downloaded at the link. The book itself is well worth reading.) None of them are binary heaps, per se, but the “leftist” heap is very similar. It has O(log n) insertion, removal, … Read more

Quicksort vs heapsort

Heapsort is O(N log N) guaranted, what is much better than worst case in Quicksort. Heapsort doesn’t need more memory for another array to putting ordered data as is needed by Mergesort. So why do comercial applications stick with Quicksort? What Quicksort has that is so special over others implementations? I’ve tested the algorithms myself … Read more

tech