Template talk:cpp/algorithm/notes heap

"heap" --> "max heap"
There are max heaps and min heaps. It is imprecise (and might be confusing to readers) to describe the max heaps of STL simply as "heaps". Thus, I'm changing "heap" to "max heap". --Extensive 12:43, 23 July 2013 (PDT)


 * Perhaps it's worth to keep the previous naming in the 'dsc' templates, as both min heap and max heap are supported by supplying appropriate ordering predicate. On the other hand, the articles should indeed mention that the default is max heap. --P12 13:02, 23 July 2013 (PDT)


 * Oh well. The thing is, the way Compare is defined ("comparison function which returns ​true if the first argument is less than the second."), the heap always will be a max heap in the terminology of the "less" comparison function, i.e. from a logical point of view, the top element will always be "not less" than its children. Inverting the comparison function will of course -- in effect -- make it a min heap, but that breaks the semantics of the comparison function being called "less". So I think your proposal has merit, but in my opinion, it would require to describe the comparison function in neutral terms, as "compare" and not as "less" and explaining that "less" will apply to a max heap and "greater" will apply to a min heap. (Possibly, this change of semantics could be limited to the heap section by calling it something like HeapCompare, but I guess that the same logic/semantic problem is present in other places referring to Compare.)  For the 'dsc' templates, it is a bit awkward to explain that the heap functions by default work on max heaps but may be "configured" to apply to min heaps, so I wouldn't be opposed to reverting my changes (except that in some places I've inserted "a" before "max heap" which I believe to be better English and thus propose to keep). --Extensive 13:29, 23 July 2013 (PDT)


 * As an afterthought: The 'dsc' template of sort explicitly mentions "ascending" (although by providing a suitable Compare it may be used to sort descending). Thus it seems that the usage of "max heap" is consistent with the sort description and thus in my opinion should be kept as it is. --Extensive 00:48, 24 July 2013 (PDT)


 * I agree -- your reasoning is solid. --P12 11:34, 24 July 2013 (PDT)