




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































David Galles Department of Computer Science University of San Francisco
Operations: Add an element Remove an element Find an element, using a key Find all elements in a range of key values
Generalized Binary Search Trees Each node can store several keys, instead ofjust one Values in subtrees between values insurrounding keys For non leaves, # of children = # of keys + 1 2 6 1 3 4 7
Generalized Binary Search Tree Each node has 1 or 2 keys Each (non-leaf) node has 2-3 children hence the name, 2-3 Trees All leaves are at the same depth
How can we find an element in a 2-3 tree?
How can we find an element in a 2-3 tree? If the tree is empty, return false If the element is stored at the root, return true Otherwise, recursively find in the appropriatesubtree
Always insert at the leaves To insert an element: Find the leaf where the element would live, if itwas in the tree Add the element to that leaf What if the leaf already has 2 elements?
Always insert at the leaves To insert an element: Find the leaf where the element would live, if itwas in the tree Add the element to that leaf What if the leaf already has 2 elements? Split!
19-11:
19-12:
When we split the root: Create a new root Tree grows in height by 1
Inserting elements 1-9 (in order) into a 2-3 tree
Inserting elements 1-9 (in order) into a 2-3 tree
Inserting elements 1-9 (in order) into a 2-3 tree 1 2 3