Designing a Hash Function
A hash function is a method that inspects the contents of an object and returns an integer value
such that
1. Objects with identical contents will return the same hash code
2
The call stack
In order to understand what happens when an exception is thrown we first need to fully examine
how method calls are handled when the program is executed. Each call to a method creates a
A binary search tree is a tree in which each node stores a key/value pair. The keys are ordered,
meaning that for any pair of keys a and b, it is possible to determine whether a<b, a>b, or a=b.
Each n
General rules:
1. a program statement that is not a method call: 1 step
2. loop executing n iterations: n * m, where m is the cost of a single loop iteration
(NOTE: m may be a function of which loop i
When searching/inserting/removing an element from a hash table, the object's hash code is first
mapped to a hash bucket, which is simply an index into the array used to represent the hash
table. The h
Deletion
Deleting a key/value pair from the tree is more complicated than inserting. If the deleted key is
in a leaf node of the tree, then there is no problem; we can just delete the node containing
As a finite series:
1 + 2 + 3 + . + N-2 + N-1
The sum of this series can be found by adding the first and last elements (1+( N-1)
= N), the second and next-to-last elements (2+( N-2) = N), and so fort
Recursion works by dividing a large problem into one or more smaller problems, and then
extending the solution to the smaller problem(s) into a solution for the large problem. For this
approach to wor
Idealized Hash Table
Before getting into the details of real hash tables, let's first consider an idealized hash table that
has guaranteed worst case running time of O(1) for insert, delete, and find.
In analyzing an algorithm, we are generally interested in its growth as N increases, rather than an
exact number of steps. Big-O refers to characterizing the growth of the exact cost T(n) of an
algori