Can a binary search tree be complete and complete?

In preparation for intermediate data structures, the professor gave us last year’s test, one of which is related to the re-arrangement of the sample tree into a full binary search tree. I tried several different versions of writing a tree, but this complete example of a binary tree from Wolfram Mathematica did not help at all, since it also matches the definition of full. The tutorial defines a complete binary tree, since the tree through level n-1 is fine with some additional leaf nodes at level n, all aligned to the left.

Nodes A E I L N O P R S T U, n = 11 nodes. Here is the best answer I came up with:

           R
         /    \
        L      T
       / \    / \
     I    N   S   U
    / \  / \
   A  E O   P

But this matches the tree example in WM, but not in the book example. So what is the correct answer?

+3
3

, , , ...

, node 0 2 .

, , , .

, , , .

, , , .

, , , .

, .

+11

, , , :

, :

        R
      /    \
     L      T
    / \    / \
  I    N   S   U
 / \  /
A  E O   

, :

        R
      /    \
     L      T
    / \    / \
  I    N   S   U
      / \
     O   P


        R
      /    \
     L      T
    / \    
  I    N   
 / \  / \
A  E O   P
+3

: T , node , .

      O
     / \
    O   O
   / \ / \
  O  O O  O
    / \
   O   O

,

Full tree: the binary tree T with n levels is completed if all levels, with the possible exception of the last, are completely full, and the last level has all its nodes on the left.

       O
      / \
     O   O
    /
   O

Full tree, but not complete

Similarly, another example

      O
     / \
    O   O
   / \ / \
  O  O O  O
 /\ /
O O O

I hope they will be useful!

+1
source

Source: https://habr.com/ru/post/1770316/


All Articles