1 / 6

2-3 Trees

2-3 Trees. Goals Design decisions Design Insertion. 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. 2-3 Trees: Design.

britain
Télécharger la présentation

2-3 Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2-3 Trees Goals Design decisions Design Insertion 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 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) CS 303 – 2-3 Trees Lecture 10

  4. 2-3 Tree: Definition < a a > a, < b b >b 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 a b a x b plus two other cases, x < a < b, and a < b < x CS 303 – 2-3 Trees Lecture 10

  6. 2-3 Trees: Insertion... And now, we need to insert the new node into the Parent, where there are 2 cases... • 2) the hard case Parent 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... CS 303 – 2-3 Trees Lecture 10

More Related