1

I've done balancing of the tree(bst>avl) requested by hand and I wonder that it was really easy, so I am not sure whether I've done it correctly.

        a
       / \
      b  e3
     / \
    e1 e2

initial state is: 'a' is parent of 'b'(left) and 'e3'(right), 'b' is a parent of 'e1'(left) and 'e2'(right).

applying right rotation gives us:

        b
       / \
     e1   a
         / \
       e2   e3

'b' in place of 'a' with child 'e1' on the left and 'a' child on the right, 'a' gets 'e2' of 'b' on the left.

So the questions:

  1. If e1 is itself a subtree or node containing other elements, can I still do this rotation?
  2. 2. If e2 and e3 are absent, can I still do this rotation?

example 11; 12;16

     16
     /
   13
  /
10

intial state: 16 is a parent of 13 and 13 is a parent of 10. Can I do from it: 13 is a parent of 10(left) and 16(right)

I know it's simplistic, but theory often does not cover these thing assuming it's clear, well not for everyone. Thanks for help,

outis
  • 75,655
  • 22
  • 151
  • 221
rotator
  • 11
  • 1

1 Answers1

0

Yes to everything, really. Think about the order property: left descendants < node and node < right descendants. Note how the rotation preserves this; compare a and b to e1, e2 and e3 before the rotation, and check the order and descendent relationships after the rotation. I'll let you ponder how before giving it away.

outis
  • 75,655
  • 22
  • 151
  • 221