{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

100_lecture28

# 100_lecture28 - Introduction to Computation and Problem...

This preview shows pages 1–5. Sign up to view the full content.

Introduction to Computation and Problem Solving Prof. Steven R. Lerman and Dr. V. Judson Harward Class 28: Class 28: Binary Search Trees Binary Search Trees 2 Binary Search Trees In the previous lecture, we defined the concept of binary search tree as a binary tree of nodes containing an ordered key with the following additional property. The left subtree of every node (if it exists) must only contain nodes with keys less than or equal to the parent and the right subtree (if it exists) must only contain nodes with keys greater than or equal to the parent. We saw that performing an inorder traversal of such a tree is would visit each node in order. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3 Goals We are going to implement a binary search tree with the usual data structure operations and then critique the implementation. including commercial databases. implementations. Generalizations of the binary search tree drive many important applications, The implementation will give you a feel for tree methods that tend to be more "visual" or "topological" than array or list 4 Keys and Values key key , but it's often useful to allow each node to contain a key and a value . The key value is extra data contained in the node key . If binary search trees are ordered, then they must be ordered on some possessed by every tree node. A node might contain nothing but the is used to look up the node. The indexed by the 2
5 Maps /value pairs maps . As an example, consider the entries in a last name first, serves as the key , and the phone number serves as the value . Such data structures with key are usually called phone book as they might be entered in a binary search tree. The subscriber name, 6 Key and Value Type class the same class and values that are instances of the same class. not Sometimes you may not need the value. But if one node has a value, you probably want to supply one for every node. We also haven't specified the type of the key and value. They can be of any you want, but all nodes should possess keys that are instances of Keys and values do have to be the same type. Our map will use generic types so you will have to declare the type of the key and value when you create the map. 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
7 Duplicate Keys identical keys? tree that prevents duplicate keys. Do we allow the tree to contain nodes with There is nothing in the concept of a binary search In the interface that we will implement, we use the keys to access the values. If we allowed duplicate keys, we wouldn't be able to distinguish between multiple nodes possessing the same key.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

100_lecture28 - Introduction to Computation and Problem...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online