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 />

Similar to case 2 except want to keep left child and any of its children.<br />

Case 4: Delete a parent with 2 children. E.g. delete Q.<br />

Problem: Can’t guarantee that the parent of the node could point to both<br />

children, since the parent may have another child of its own.<br />

AVL Tree<br />

In an AVL, the difference between the right and left sub‐tree can never be more<br />

than 1, throughout the tree.<br />

A binary search tree (BST) is an AVL tree if and only if, for every node in the tree,<br />

the difference between maximum height of the right sub‐tree minus the<br />

maximum height of the left sub‐tree is less than 2.<br />

That is the difference can be ‐1, 0, or <strong>1.</strong><br />

AVL Trees is An ordered tree (binary search tree) is used when we wish to store<br />

objects with (numerical) keys in a binary tree so that lookups can be done in<br />

order log 2N time, where N is the number of objects in the tree. But an ordered<br />

tree that is seriously ``unbalanced,'' that is, where paths from the root to the<br />

leaves have dramatically different lengths, will ruin the desired lookup<br />

behavior.<br />

The worst‐case example of an unbalanced ordered tree is the tree built by<br />

inserting a sorted sequence of objects (we show the numerical keys only; the<br />

objects attached with the keys are unimportant):<br />

1 2 3 4<br />

The tree looks like this:<br />

1<br />

/ \<br />

. 2<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!