Search code examples
javaheapcbt

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


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

Solution

  • 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