Here I build the heap following two methods:
Can I get multiple complete binary trees for a given array?
- Method 1 - Insertion;
- Method 2 - Sub trees
Here I build the heap following two methods:
Can I get multiple complete binary trees for a given array?
Copyright © 2021 Jogjafile Inc.
Yes, you can get different complete binary trees as heaps for the same data, depending of the method you use to build the heap.
Note that the first (insertion) method [Williams’ method] is less efficient than the second [Floyd’s method], but they both produce a correct heap, even though they are not equal. See Wikipedia: building a heap