Download presentation
Presentation is loading. Please wait.
1
Goals Design decisions Design Insertion
2-3 Trees Goals Design decisions Design Insertion 5/22/2019 CS 303 – 2-3 Trees Lecture 10
2
2-3 Trees: Goals Goal – Almost Balanced Tree with leaves sorted Why?
Balanced -> O(log n) speed Sorted speeds INSERT/DELETE often required by the application, anyway 5/22/2019 CS 303 – 2-3 Trees Lecture 10
3
2-3 Trees: Design Values stored at leaves (not at internal nodes!)
Interior nodes have either 2 or 3 children (never only 1) Restructure as needed to keep all paths from root to leaf the same length (or nearly so) 5/22/2019 CS 303 – 2-3 Trees Lecture 10
4
2-3 Tree: Definition a b < a a > a, < b b >b 5/22/2019
CS 303 – 2-3 Trees Lecture 10
5
2-3 Trees: Insertion To insert x Search for x
At lowest interior level, there are two cases: 1) the easy case x b b a b a x b plus two other cases, x < a < b, and a < b < x 5/22/2019 CS 303 – 2-3 Trees Lecture 10
6
2-3 Trees: Insertion... 2) the hard case
And now, we need to insert the new node into the Parent, where there are 2 cases... 2) the hard case Parent x c b c a b c a x b c plus three other cases: x < a < b < c, a < b < x < c, and a < b < c < x Do an example, e.g. insert 5,2,7,0,3,4,6,1,8,9... 5/22/2019 CS 303 – 2-3 Trees Lecture 10
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.