I am currently reading this document and on page 5 discusses the properties of binary heaps, which he considers generally known. However, one of the things they do is that I have not seen before and cannot understand. The authors claim that if you are given a balanced binary heap, you can list the elements of this heap in sorted order by O (log n) time for each element using a standard width search. Here is their original wording:
In a balanced heap, any new item can be inserted at logarithmic time. We can list heap elements by weight, taking logarithmic time to generate each element, simply using a width search.
I'm not sure what the authors mean. The first thing that comes to mind when they say โwidth searchโ will be the first search for tree elements starting with the root, but not guaranteed to list the elements in sorted order and does not require logarithmic time per element. For example, running BFS on this mini-heap causes items to fail regardless of how you break the links:
1 / \ 10 100 / \ 11 12
This always indicates 100 to 11 or 12, which is clearly wrong.
Am I missing something? Is there a simple width search you can do on the heap to get items in sorted order using logarithmic time each? Clearly, you can do this by destructively modifying the heap, removing the minimum element each time, but the intention of the authors seems to be that this can be done without destruction.
source share