This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Topic 1. Binary Search Trees CSE 2011
Prof. J. Elder 6 Last Updated: 4/1/10 2:37 PM Binary Search Trees
Insertion
Deletion
AVL Trees
Splay Trees CSE 2011
Prof. J. Elder 7 Last Updated: 4/1/10 2:37 PM Binary Search Trees
A binary search tree is a binary tree storing keyvalue entries at its
internal nodes and satisfying the following property:
Let u, v, and w be three nodes such that u is in the left subtree of v and w is
in the right subtree of v. We have key(u) key(v) key(w) The textbook assumes that external nodes are ‘placeholders’: they do
not store entries (makes algorithms a little simpler)
An inorder traversal of a binary search trees visits the keys in
increasing order
Binary search trees are ideal for dictionaries with ordered keys.
6
2
1 CSE 2011
Prof. J. Elder 9
4 8 8 Last Updated: 4/1/10 2:37 PM Binary Search Tree
All nodes in left subtree Any node All nodes in right subtree 38 25 51 17 4 31 21
CSE 2011
Prof. J. Elder 28 42 35 40
9 63 49 55 71 Last Updated: 4/1/10 2:37 PM Search: Define Step
Cut subtree in half.
Determine which half the key would be in.
Keep that half. 38 key 17
25 51 17 4 If key < root,
then key is
in left half.
CSE 2011
Prof. J. Elder 31 21 28 If key = root,
then key is
found
 10  42 35 40 63 49 55 71 If key > root,
then key is
in right half.
Last Updated: 4/1/10 2:37 PM ...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Binary Search, Data Structures

Click to edit the document details