Unformatted text preview: Delete algorithm, because it is too complex for this text. We have also ignored the concept length that must accompany the tree if it is to be used to implement a list. Rather than keep track of the number of items in the tree as we build it, let’s write an algo-rithm to count the number of nodes in the tree. How many nodes are there in an empty tree? Zero. How many nodes are there in any tree? One plus the number of nodes in the left subtree and the number of nodes in the right subtree. This definition leads to a recur-sive definition of the length operation. Length(tree) If (tree is null) return 0 Else return Length(left(tree)) + Length(right(tree)) + 1...
View Full Document
- Fall '10
- Graph Theory, Right-wing politics, Left-wing politics