Can I get multiple complete binary trees for a given array by different methods?

Viewed 28

Here I build the heap following two methods:

hand solution

Can I get multiple complete binary trees for a given array?

  • Method 1 - Insertion;
  • Method 2 - Sub trees
1 Answers

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

Related