=========================================================================== CSC 263H Tutorial Outline for Week 3 Winter 2004 =========================================================================== ------------------- Binary Search Trees [section 3.1] ------------------- You've all seen binary search trees in CSC148H/A58H before, but let's review their definition and how to perform SEARCH, INSERT, and DELETE operations on them. Assume each node x of a binary tree has fields parent[x], left[x], right[x], and key[x], and a tree T is given by a pointer to its root (root[T]). A binary tree is a BST if it satisfies the "BST property": [[Q: state the ordering property for BST's.]] [[Q: describe the SEARCH algorithm for BST's.]] Running time? In the worst-case, since the algorithm only examines nodes in a single path from the root down to a leaf, it's O(height of the tree). [[Q: describe INSERT algorithm for BST's.]] [[Q: describe DELETE algorithm for BST's.]] [[Q: think of algorithms for operations MIN/MAX (find smallest/largest value in tree) and PRED/SUCC (find predecessor/successor of any value in tree).]] Worst-case running time for all these operations is O(height(T)). Unfortunately, height(T) can be as bad as n so in the worst-case, all operations could take time Omega(n).