Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.

Similar presentations


Presentation on theme: "1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in."— Presentation transcript:

1 1 Section 9.2 Tree Applications

2 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in which each vertex is labeled with a key value –the key value of a vertex is larger than all key values in its left subtree, and smaller than all key values in its right subtree

3 3 Recursive procedure for building a BST from list of key values Start with tree containing one vertex (root) - first item in list is assigned as root’s key To add a new item: –compare value to keys already in tree, starting at root –if value is less than current key, move left; if greater, move right –when value is less than current key and current vertex is a leaf, then create new vertex with value as key and insert as current vertex’s left child –when value is greater, insert as current vertex’s right child

4 4 Example 1 Enter the following values into a binary search tree: 14, 9, 26, 7, 12, 34, 5, 2, 16

5 5 Decision Trees Rooted trees can be used to model problems in which a series of decisions leads to a solution Each internal vertex is a decision point, and each leaf represents a possible outcome

6 6 Section 9.2 Tree Applications


Download ppt "1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in."

Similar presentations


Ads by Google