notes91

notes91 - As the restructuring may upset the balance of a...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
AVL TREES An AVL tree is a tree wherein at most, the difference in height between bottom nodes is 1. Because of this, the tree needs to be frequently restructured. Restructuring z - node that is the root of the unbalanced tree y- the child of z with highest height x - the child of y with the highest height Rename z, y, and x as a, b, and c based on the order of the inorder traversal. Restructure tree as: We now have 4 cases: 1.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. 3. double rotation 4. double rotation
Background image of page 2
note: There is not fifth case. It is already balanced. Balancing Removing a node can cause the tree to become unbalanced. Assuming the removed node is w, we find the first unbalanced node while traveling up the tree from w. Apply the restructure algorithm to restore balance in that node.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: As the restructuring may upset the balance of a node higher in the tree, we continue checking for balance until the top is reached. Example 1 remove 32 This is not an AVL tree. It needs to be restructured. find x, y, and z The result, in this case, is a balanced tree; the height of all children differ by at most 1. Example 2: removal of the root Remove 62 Find the right most node in the left child of the node to be removed and move it to fill the hole. Implementation Each node stores left, right, and parent. Also, storing the neighbor in each node speeds of the test for restructuring. Insert, find, and remove always have O (log n ) in AVL trees compared to O( n ) in lists and hash tables (in the word case)....
View Full Document

Page1 / 5

notes91 - As the restructuring may upset the balance of a...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online