Binary Search Trees-1
Binary Search Trees-1
Recap….
• Binary tree: A binary tree is defined
recursively.
• A binary tree T is a structure defined on finite
set of nodes that either
– Contains no nodes (the empty tree or null tree)
denoted NIL or
– Composed of three disjoint set of nodes:
• a root node
• a binary tree called its left subtree
• a binary tree called its right subtree
Reading Exercise
• Example of a Binary Tree:
// Case 1
// Case 2
Trace the pseudo code to find the
successor of 4
Trace the pseudo code to find the
successor of 9
Running time
• The running time of TREE-SUCCESSOR on a tree
of height h is O(h), since we either follow a
simple path up the tree or follow a simple path
down the tree.
• The procedure TREE-PREDECESSOR, which is
symmetric to TREE-SUCCESSOR, also runs in
time O(h)
Exercise
• Write the pseudo-code for TREE-PREDECESSOR(x)