Programming Contest

 

 

Review for Exam 1

Fall 2004

You may have one sheet of notes

 

Chapters from Carrano/Savitch

•      Chapters 17    Dictionaries

•      Chapter 18      Dictionary Implementation

•      Chapter 19      Hashing

•      Chapter 24      Trees

•      Chapter 25      Tree implementations

•      Chapter 26      A BST Implementation

•      Chap 27          A Heap Implementation

 

Lecture Topics

•     Major categories

–  Java programming

–  Dictionaries

–  Hashing

–  Trees

–  Heaps

 

Lab topics

•      Use the Sorted Dictionary class

•      Create a simple hash table

•      Use the HashMap class

•      Tree Concepts

•      Implement a thesaurus using hashing

•      Vary the hash function & collision resolution

•      Build a BST

 

Java review

•      Mostly done looking at the Dictionary class

–   Java file I/O

–   Java interfaces

•   Comparable interface

•   Iterator interface

–   Difference between interfaces & abstract classes

–   Interfaces

–   StringTokenizer

–   Iterators

–   Writing generic code

 

Dictionary ADT

•      A dictionary uses a key to retrieve information that is related to the key

•      The dictionary can be implemented several ways

–    Sorted array

–    Sorted linked list

–    Hash table

–    Binary search tree

•      We looked at two Dictionary classes that implemented a dictionary interface

–    One objective in doing that was to review different Java constructs

–    The other was to become familiar with the Dictionary ADT

 

Hashing

•      General idea of hashing

•      Hash functions

•      Time complexity of perfect hashing

•      Collision resolution methods

•      Load factor

 

Hash functions

•       Criteria for good hash functions

–    Quick and easy to compute

–    Minimize the number of collisions

–    Achieve an even distribution of the records across the range of indices (uniform hashing function)

•      Writing a hash function

–   First, convert the key to an integer

•   Many ways to do this

•   Using a polynomial hash code for strings seems to work well

–  Use Horner’s method to evaluate the polynomial

–   Then, compress to size of the array

 

Collision resolution methods

•      Open address

–    Advantages & disadvantages

–    Types

•    Linear probing

•    Quadric probing

•    Double hashing

•      Separate chaining

–    Advantages & disadvantages

•      I may ask you about what you did for your hashing lab, and the results.

 

Load factor

•      Optimal depends on the type of collision resolution

•      Open addressing should be about 0.5

•      Separate chaining can go as high as 1 or 2 without much degradation

–   Books seem to recommend .75

 

Rehashing

•      If the load factor gets too high, the table should be rehashed

•      This involves

–   Doubling the table size

–   Sending all the keys through the new hash function

 

Trees

•      Definitions of leaf, path, height, parent, child

•      Full m-ary trees

–   Definition?

–   Theorems about relationships between

m:  # children,

i:  # interior nodes

n:  # total nodes

L:  # leaves

 

Tree traversal & recursion

•      Inorder

–   Recursively visit all nodes in the left subtree

–   Process the root node

–   Recursively visit all nodes in the right subtree

•      Preorder

–   Process the node, go left, then go right

•      Postorder

–   go left, then go right, then rocess the node,

 

 

Binary Trees

•      Every node has at most two children

•      Types of binary trees           

–   Expression trees

–   Binary Search Trees

–   Heaps

•      As long as the tree stays balanced, the height of the tree is the log of the number of (nodes +1)

•      If you have a full binary tree with 127 nodes, what is its height?

 

–   Log 128 = 7;     27=128

Binary Search Trees

•     Ordering

•     Know how these operations work and the time complexity (but do not feel you must be able to reproduce the code)

–  Adding

–  Deleting

–  Searching

 

Heaps

•      Heap order property

•      Heap structure property

•      How heaps are stored in the machine

•      Adding an element to a heap

•      Deleting the max or min element from a heap

•      Time complexity of the major operations of a heap