Computer Science, asked by cnrkrishna4872, 4 months ago

Construct AVL tree for the elements 63,9,19,2718,108,99,81.List the leaf nodes

Answers

Answered by pulkitsahu103
0

Answer:

you play free fire plese follow me

Answered by sadiaanam
0

Answer:

To construct an AVL tree, we follow these steps :

  1. Create the root node and add the first element 63 to it.
  2. Add the next element 9 to the tree, which is smaller than 63. As there are no other nodes in the tree, 9 becomes the left child of 63.
  3. Add the next element 19, which is also smaller than 63. Since 19 is greater than 9, it becomes the right child of 9.
  4. Add the next element 27 to the tree. It is greater than 19, so it becomes the right child of 19.
  5. Add the next element 18 to the tree. It is smaller than 19, so it becomes the left child of 19. However, this insertion causes an imbalance in the tree, as the height of the left subtree of 19 is 2 and the height of the right subtree is 0.

Explanation:

To restore the balance, we perform a left rotation at node 9, which becomes the new root of this subtree. The new tree looks like this:

          63

         /  \

        18   9

            / \

           19  27

Add the next element 108 to the tree. It is greater than 63, so it becomes the right child of 63. The tree looks like this now:

          63

         /  \

        18   108

            / \

           9  27

             \

             19

Add the next element 99 to the tree. It is greater than 63 but smaller than 108, so it becomes the left child of 108. The tree looks like this now:

          63

         /  \

        18   108

            / \

           9  99

             / \

            27 19

Add the final element 81 to the tree. It is greater than 63 but smaller than 108, so it becomes the left child of 99. The tree looks like this now:

          63

         /  \

        18   108

            / \

           9  99

             / \

            27 81

                \

                19

The leaf nodes of this AVL tree are 18, 27, 19, and 81.

Learn more about AVL tree :

https://brainly.in/question/3908874

#SPJ2

Similar questions