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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

/ \<br />

. 3<br />

/ \<br />

. 4<br />

/ \<br />

. .<br />

Obviously, a lookup in this tree is just a linear search, which is slower than log‐<br />

time.<br />

How can we maintain an ordered tree so that, regardless of the order of<br />

insertions, the tree remains balanced? There are several sophisticated<br />

technques for doing so; here we consider one of the most elegant, AVL trees.<br />

Definition of an AVL tree<br />

(For example, if the tree held 2048 An AVL‐tree is an ordered tree that has the<br />

height-balanced property. Here are the basic definitions:<br />

The height of a tree is the length of the longest path from the tree's root<br />

to one of its leaves.<br />

A Node is balanced if the height of its left subtree is plus‐or‐minus‐one<br />

the height of its right subtree.<br />

A binary tree has the height-balanced property if all of its Nodes are<br />

balanced<br />

According to this definition, the following is NOT an AVL tree, because the root<br />

node (A) has a balance of 2. Balances of 0 are not shown.<br />

A (3‐1 = 2)<br />

B C (2‐1 = 1)<br />

D E (1‐0 = 1)<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

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

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

Saved successfully!

Ooh no, something went wrong!