lecture05-RBTree

# lecture05-RBTree - Sources Dr David Luebke’s slides Dr...

This preview shows pages 1–7. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Sources: Dr. David Luebke’s slides Dr. Dan Gildea’s slides CS 6713 Advanced Analysis of Algorithms Lecture 05 Red-Black Trees Review: Binary Search Trees ● Binary Search Trees (BSTs) are an important data structure for dynamic sets ● In addition to satellite data, elements have: ■ key : an identifying field inducing a total ordering ■ left : pointer to a left child (may be NULL) ■ right : pointer to a right child (may be NULL) ■ p : pointer to a parent node (NULL for root) Review: Binary Search Trees ● BST property: key[left(x)] ≤ key[x] ≤ key[right(x)] [all the keys in x’s left subtree] ≤ key[x] ≤ [all the keys in x’s right subtree] ● Example: F B H K D A Review: Inorder Tree Walk ● An inorder walk prints the set in sorted order: TreeWalk(x) TreeWalk(left[x]); print(x); TreeWalk(right[x]); ■ Easy to show by induction on the BST property ■ Preorder tree walk : print root, then left, then right ■ Postorder tree walk : print left, then right, then root Review: BST Search TreeSearch(x, k) if (x = NULL or k = key[x]) return x; if (k < key[x]) return TreeSearch(left[x], k); else return TreeSearch(right[x], k); Review: BST Search (Iterative) IterativeTreeSearch(x, k) while (x != NULL and k != key[x]) if (k < key[x]) x = left[x]; else x = right[x]; return x; Review: BST Insert...
View Full Document

{[ snackBarMessage ]}

### Page1 / 18

lecture05-RBTree - Sources Dr David Luebke’s slides Dr...

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

View Full Document
Ask a homework question - tutors are online