Search Trees_Part_6

# Search Trees_Part_6 - Insertion Trinode Restructuring Case...

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

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Insertion: Trinode Restructuring - Case 2 height =h z h-1 y Restructure T0 y h-3 T1 h-1 h-2 z h-2 x x h-2 h-3 h-3 T2 T3 h-3 T0 T1 T2 T3 one is h-3 & one is h-4 one is h-3 & one is h-4 CSE 2011 Prof. J. Elder - 26 - Last Updated: 3/3/10 6:14 PM Insertion: Trinode Restructuring - Case 3 height =h z h-1 x Restructure h-1 h-3 T0 y h-2 h-3 T3 h-2 y h-2 x T1 h-3 T2 T0 T1 T2 z h-3 T3 one is h-3 & one is h-4 one is h-3 & one is h-4 CSE 2011 Prof. J. Elder - 27 - Last Updated: 3/3/10 6:14 PM Insertion: Trinode Restructuring - Case 4 height =h z h-1 x Restructure T0 h-3 y h-1 x h-2 T1 T3 h-2 z h-2 h-3 h-3 T2 T0 T1 T2 y h-3 T3 one is h-3 & one is h-4 one is h-3 & one is h-4 CSE 2011 Prof. J. Elder - 28 - Last Updated: 3/3/10 6:14 PM Insertion: Trinode Restructuring - The Whole Tree Do we have to repeat this process further up the tree? No! The tree was balanced before the insertion. Insertion raised the height of the subtree by 1. Rebalancing lowered the height of the subtree by 1. Thus the whole tree is still balanced. height =h z y h-1 Restructure h-1 h-2 T0 CSE 2011 Prof. J. Elder x y h-3 h-3 T2 h-2 x h-2 h-3 T0 T1 z h-3 T2 one is h-3 & one is h-4 T1 one is h-3 & one is h-4 T3 - 29 - Last Updated: 3/3/10 6:14 PM T3 Removal Imbalance may occur at an ancestor of the removed node. height = 3 2 1 0 7 Remove(8) 1 4 1 3 0 height = 3 0 5 0 1 0 0 CSE 2011 Prof. J. Elder 2 8 0 - 30 - 0 0 4 Problem! 1 3 0 7 5 0 Last Updated: 3/3/10 6:14 PM ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 5

Search Trees_Part_6 - Insertion Trinode Restructuring Case...

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

View Full Document
Ask a homework question - tutors are online