CS223-0131-BST

CS223-0131-BST - Binary Search Tree Neil Tang 01/31/2008...

Info iconThis preview shows pages 1–10. 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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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: 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 = N-1 = 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

Page1 / 10

CS223-0131-BST - Binary Search Tree Neil Tang 01/31/2008...

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

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