Searching and Hashing

14 flashcardsby MariaE
Study these flashcardsFree · spaced repetition · iPhone, Android, Mac & web

All cards

1
Most hash tables are not full.
  • TRUE
  • FALSE
2
Any function can be a hash function if it produces an integer that is suitable to be used as an array index.
  • TRUE
  • FALSE
3
If a class overrides the method equals, it should not override the method hashCode.
  • TRUE
  • FALSE
4
If the method equals considers two objects to be equal, then the method hashCode must return the same value for both objects.
  • FALSE
  • TRUE
5
Calling the method hashCode more than once on an object that has not been altered should return the same value.
  • FALSE
  • TRUE
6
The size of a hash table should always be an even number.
  • TRUE
  • FALSE
7
In open addressing with linear probing, a successful search for an entry that corresponds to a given search key could potentially follow a different probe sequence used to add the entry to the hash table.
  • FALSE
  • TRUE
8
True or False
  • TRUE
9
Calculate the hash code for “ACE” with g = 7, given Unicode 'A' = 65, 'C' = 67, 'E' = 69
Answer: 65 * 9 + 67 * 3 + 69 * 1 = 855
10
Given a hash table length of 29, what index will the value 371 map to?
Answer: 371 % 29 = 23
11
What is λ for a hash table with 500 locations and 200 entries that uses open addressing?
Answer: 200 / 500 = 0.40
12
What are the two categories for collision resolution?
[A] Linear Probing [B] Buckets
13
Which of the following are 4K+3 prime numbers? a) 6863 b) 857
a) 6863 YES b) 857 NO
14
Given the following possible implementations of the hashCode method, which of these would be valid implementations for a class's hashCode method?
  • @Override
    public int hashCode() {
    return 42;
    }
  • @Override
    public int hashCode() {
    return this.id;
    }
  • @Override
    public int hashCode() {
    return this.name.hashCode() * 31 + this.age;
    }
  • @Override
    public int hashCode() {
    return (int) (Math.random() * 1000);
    }
Study all 14 cards for free