
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

4b example. Prove that we can create a 4-element heap in at most three comparisons. Assume we have 4 elements: a, b, c, and d Step 1: Compare a and b. Without loss of generality (WLOG), assume that a < b. Then we have the heap: a b Step 2: Compare c and d. Without loss of generality (WLOG), assume that c < d. Then we have the heap: c d Step 3: Compare a and c. WLOG, assume that a < c. Then we have the heap: a c b d This is a heap of size four. Note that we can switch the children around since there is no difference between being a left or right child in a heap structure. You can extend this idea to create a size 8 heap. It may be helpful for you to create a non-binary (i.e.
2 children heap as an intermediate step and figure out how you can use one or more comparisons to fix it into a binary heap.