Short Answers Section 11.1 Serial Search and Binary Search |
A. About how big should the array be if I use open
addressing with linear probing? NOTE: For a load factor of
A, the average number of accesses
is generally ½(1+1/(1-A)).
B. About how big should the array be if I use chained hashing?
NOTE: For a load factor of
A, the average number of accesses
is generally (1+A/2).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Suppose that we are doing a serial search for an element. Circle
any elements that will be found by examining two or fewer numbers from the
array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Suppose that we are doing a binary search for an element. Circle
any elements that will be found by examining two or fewer numbers from the
array.
public static boolean has42(int[ ] data, int start, int end)
// Precondition: The elements data[start]...data[end] are sorted from smallest
// to largest. This array segment might be empty (indicated by end being less
// than start).
// Postcondition: A true return value indicates that the number 42 appears in
// data[start]...data[end]. A false return value indicates that 42 doesn’t
// appear.
Short Answers
Section 11.2
Open-Address
Hashing
Short Answers
Section 11.3
Chained
Hashing
public void Table remove(Object key)
{
ChainedHashNode cursor;
int i;
1. i = key.hashCode( );
2. Make cursor refer to the node that contains an item with the given key
(or set it to null if there is no such node).
3. if (cursor != null)
{
3a. _____________________________________________________________
3b. _____________________________________________________________
}
public class Table
{
private int manyItems;
private Object[ ] keys;
private Object[ ] data;
private boolean[ ] hasBeenUsed;
...
The hash table uses open addressing with linear probing.
A location [i] of the table that has NEVER been used will have hasBeenUsed[i] set to false.
Other locations have hasBeenUsed[i] set to true.
Complete the implementation of the following method of the Table class.
There is no need to check the precondition, but your code must be
as efficient as possible.
public boolean containsKey(Object key)
// Postcondition: If key occurs as a key of a record in the table, then
// the method returns true; otherwise the method returns false.
Short Answers
Section 11.4
Time Analysis
of Hashing
Multiple Choice Section 11.1 Serial Search and Binary Search |
Multiple Choice
Section 11.2
Open-Address
Hashing
Multiple Choice
Section 11.3
Chained
Hashing
Multiple Choice
Section 11.4
Time Analysis
of Hashing