{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

notes93 - CS251 Week of March 8th 1(2-4 Trees 2 Red-Black...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS251: Week of March 8th 1. (2-4) Trees 2. Red-Black Trees 2-23-04: (2-4) Trees I. Characteristics of (2-4) Trees Each node can have up to 4 children, and at most 3 keys Searchable keys are matched to each piece of data, and used to order the tree All children must have same depth, or tree is unbalanced II. Operations of a (2-4) Tree A. Search 1. Start from root 2. If key being searched ("searchKey") < first key in the current node (K[first]), descend into the leftmost child 3. If searchKey > K[last], descend into rightmost child 4. Otherwise, compare with remaining keys, descending as appropriate 5. Once descended to node in lower level, check keys for a match 6. If no match, repeat 2-5 B. Insert 1. Insert key at lowest available node 2. Nodes with 1-2 keys will just receive a new key 3. 3-key Nodes must be split to accept a new key: o Considering all 4 key values, move one of the middle keys (#2 or #3, arbitrarily) up to the parent node o Repeat upwards if this causes parent to have 4 keys 4. If root overflows (has > 3 keys), split root into 3 nodes, and create 2 levels (one parent, two children) Time complexity: Searching for location to insert: O(log n) Balancing tree (worst case): O(log n) Splitting root & creating new level, if necessary: O(1) Total insertion operation: O(log n + log
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern