Section 5.3: Decision Trees

Abstract:

Decision trees are defined, and some examples given. Binary search trees store data conveniently for searching later. Some bounds on worst case scenarios are established.

Decision Tree Definition and Terminology

Definition: a decision tree is a tree in which

Examples of decision trees in action

Exercise #2, p. 388/394 (how do we modify Figure 5.51/5.52?).

Practice 24, p. 383/390.

Lower Bounds on Searching

In particular about binary trees:

  1. Any binary tree of depth d has at most tex2html_wrap_inline160 nodes. (Proof: look at the full binary tree, as it has the most nodes per depth.)
  2. Any binary tree with m nodes has depth tex2html_wrap_inline164 , where tex2html_wrap_inline166 is the floor function, meaning the greatest integer less than or equal to x. Again, the proof can be motivated simply by looking at the full binary tree situation:

       table72
    Table: Adding one more node bumps the depth up 1, so that if there are tex2html_wrap_inline170 nodes, the depth is d. Hence, in the case of powers of 2, tex2html_wrap_inline174 .

    A more formal proof is by contradiction and interesting (p. 384/390):

    By contradiction, tex2html_wrap_inline164 .

These facts lead to the following

Theorem (on the lower bound for searching):

Any algorithm that solves the search problem for an n-element list by comparing the target element x to the list items must do at least tex2html_wrap_inline204 comparisons in the worst case.

If, in its worst case, an algorithm does at most this lower bound on worst case behavior is an optimal algorithm in its worst-case behavior. Binary search is optimal (based on Practice 24!).

Binary Search Tree

The Binary search algorithm required a sorted list; if your data is unsorted (it may be changing dynamically in time, if you are updating a database of customers, for example), you can populate a tree which approximates a sorted list, and then use a modified search algorithm (binary tree search) to search the list. A binary search tree is constructed as follows:

For example, Figure 5.54/5.55:

Practice #25, p. 386/392.

The binary tree search algorithm works in the same way as you'd introduce a new node, only the algorithm terminates if

In this case the binary search tree serves as the decision tree for the binary tree search algorithm.

Exercise #9, p. 389/395.

Sorting

Examine Figure 5.55/5.56, p. 387/393:

In this case, we're sorting a three-element list using a decision tree. The author calls this a stupid algorithm (actually, ``not particularly astute''): why?

(Practice #26, p. 387/393. How would we modify Figure 5.55/5.56?)

Assuming no equal elements in the list, then this is indeed a binary (rather than ternary tree, with = included). In this case, we can also get a lower bound on sorting a list with n elements:

This is the Theorem on the lower bound for sorting: that you have to go to at least a depth of tex2html_wrap_inline230 in the worst case.

LONG ANDREW E
Fri Oct 25 10:31:07 EDT 2002