Summary Lecture Exercise Programming Exercise Objectives Introduction

J.E.D.I Figure 1.158 Insertion into an AVL Tree

9.5 Summary

• A Binary Search Tree is a binary tree that satisfies the BST property • Operations on BSTs include insertion of a new key, deletion of an existing key, and searching for a key • The BST search algorithm runs in Olog2 n time on the average and On time on the worst case • Balanced BSTs ensure that searching takes Olog2 n • An AVL tree is a height-balanced tree wherein the height difference between the subtrees of a node for every node in the tree is at most 1 • Rotations have to be performed during insertion and deletion in an AVL tree to maintain its balance Data Structures 184 J.E.D.I

9.6 Lecture Exercise

1. Insert the following keys in an AVL tree, based on the order given: a 1 6 7 4 2 5 8 9 0 3 b A R F G E Y B X C S T I O P L V

9.7 Programming Exercise

1. Extend the BST class definition to make it an AVL tree, i.e., class AVL extends BST{ } Override the insert and delete methods to implement the rotations in an AVL tree to maintain the balance. Data Structures 185 J.E.D.I 10 Hash Table and Hashing Techniques

10.1 Objectives

At the end of the lesson, the student should be able to: • Define hashing and explain how hashing works • Implement simple hashing techniques • Discuss how collisions are avoidedminimized by using collision resolution techniques • Explain the concepts behind dynamic files and hashing

10.2 Introduction

Hashing is the application of a mathematical function called a hash function to the key values that results in mapping the possible range of key values into a smaller range of relative addresses. The hash function is something like a locked box that needs a key to get the output which, in this case, is the address where the key is stored: key ==== Hash Function Hk === address With hashing, there is no obvious connection between the key and the address generated since the function randomly selects an address for a specific key value, without regard to the physical sequence of the records in the file. Hence, it is also known as randomizing scheme. Two or more input keys, say k 1 and k 2 , when applied to a hash function, may hash to the same address, an accident known as collision. Collision can be reduced by allocating more file space than the minimum required to store the number of keys. However, this approach leads to wasted space. There are several ways to handle collisions, which will be discussed later. In hashing, there is a need to choose a good hash function and consequently, select a method to resolve, if not eliminate, collisions. A good hash function performs fast computation, in time complexity of O1, and produces less or no collisions. Data Structures 186 J.E.D.I

10.3 Simple Hash Techniques