10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

2. A right rotation.<br />

Suppose we begin with the following AVL tree.<br />

2 6<br />

8<br />

4 9<br />

Now suppose that we want to insert the value 3.<br />

If we do a normal insert, we now have a problem, because the resulting tree is<br />

not an AVL tree.<br />

8 (‐2)<br />

4 (‐1) 9<br />

2 (1) 6<br />

3<br />

To correct this situation, we need to do a right rotation of 8.<br />

This requires:<br />

(1) 4 is promoted, replacing 8.<br />

(2) This orphans 4’s right child (6), but:<br />

(3) 8 becomes 4’s right child and adopts 6 as a left child<br />

This yields the following tree:<br />

4<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 204 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!