Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

4.

2 Binary Trees
A binary tree is a tree in which no node can have more than two children. An analysis shows that the average depth is O(N), and that for a special type of binary tree, namely the binary search tree, the average value of the depth is O(logN).

The property that makes a binary tree into a binary search tree is that for every node, , in the tree, the values of all the items in its left subtree are smaller than the item in , and the values of all the items in its right subtree are larger than the item in .

The general strategy is to replace the data of this node with the smallest data of the right subtree (which is easily found) and recursively delete that node (which is now empty). !ecause the smallest node in the right subtree cannot have a left child, the second remove is an easy one. "igure #.$# shows an initial tree and the result of a deletion. The node to be deleted is the left child of the root% the key value is $. &t is replaced with the smallest data in its right subtree ('), and then that node is deleted as before.

4.4 AVL Trees


An AVL (Adelson()elskii and *andis) tree is a binary search tree with a balance condition. The balance condition must be easy to maintain, and it ensures that the depth of the tree is O(logN). The simplest idea is to re+uire that the left and right subtrees have the same height. Another balance condition would insist that every node must have left and right subtrees of the same height. An AVL tree is identical to a binary search tree, e,cept that for every node in the tree,the height of the left and right subtrees can differ by at most -.

Sets
The Set interface represents a Collection that does not allow duplicates. A

Maps
A Map is an interface that represents a collection of entries that consists of keys and their values.

The implementation of hash tables is fre+uently called hashing. .ashing is a techni+ue used for performing insertions, deletions, and searches in constant average time. The ideal hash table data structure is merely an array of some fi,ed si/e, containing the items.

You might also like