notes93 - CS251: Week of March 8th 1. (2-4) Trees 2....

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 n + 1) = O(log n)...
View Full Document

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 4

notes93 - CS251: Week of March 8th 1. (2-4) Trees 2....

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

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