This preview shows pages 1–10. 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 DocumentThis 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 DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Binary Search Tree
Neil Tang 01/31/2008 CS223 Advanced Data Structures and Algorithms 1 Class Overview Definition Operations: contains, findMin, findMax, insert, remove Time complexity analysis CS223 Advanced Data Structures and Algorithms 2 Definition A Binary Search Tree is a special binary tree in which for each node X, the values of all the items in its left subtree are smaller than that in X and the values of all the items in its right subtree are larger than that in X. CS223 Advanced Data Structures and Algorithms 3 Operations contains: find out if a binary search tree contains a given item x. CS223 Advanced Data Structures and Algorithms 4 Operations findMin/findMax: find the smallest/largest item in a binary search tree. CS223 Advanced Data Structures and Algorithms 5 Operations insert: insert an item into a binary search tree.
12 5 2 12 14 5 2 9 13 15 17 18 19 9 13 15 17 18 19 14 CS223 Advanced Data Structures and Algorithms 6 Operations CS223 Advanced Data Structures and Algorithms 7 Operations remove: delete an item in a binary search tree.
5 15 12 10 6 7 5 3 10 6 7 5 15 12 10 6 7 7 13 18 16 20 23 3 10 6 12 13 18 15 16 20 23 3 10 6 7 15 12 13 18 13 18 16 20 23 3 10 6 7 5 12 13 15 18 20 23 15 5 12 16 20 18 23 3 Case 1: Case 2: Case 3: 3 5 16 20 23 CS223 Advanced Data Structures and Algorithms 8 Operations CS223 Advanced Data Structures and Algorithms 9 Time Complexity Analysis
The time complexities of almost all operations on a binary search tree are O(d), where d is the depth (height) of the tree. d = 3 = log(N+1)1 = O(logN) d = 7 = (N+1)/2  1 = O(N) d = N1 = O(N) Theorem: The average height of a randomly built (insertion) binary search tree on N keys is (logN) . (pp.268 Cormen's book)
CS223 Advanced Data Structures and Algorithms 10 ...
View Full
Document
 Spring '07
 Tang
 Algorithms, Binary Search, Data Structures

Click to edit the document details