HashTable Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a hashcode?

A

A hashcode is used to create a key for an item.

The hashcode may be the same as the value of the item or may involve the use of some elaborate formula in hopes of creating a unique key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the output of the code?

Character c = new Character('a');
out.println(c.hashCode());
c = new Character('0')
;out.println(c.hashCode());
c = new Character('A');
out.println(c.hashCode());
A

97
48
65

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a hash table?

A

A hash table stores values based on the hash code of each value.

Most hash tables are built using an ARRAY of LINKED LISTS.

HashSet and HashMap were both created around hash tables.

Yet, Hash Tables are similar to Maps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s an example of a hash table?

A

Object[] hashTable = new Object[10];

Character c = new Character(‘l’);
hashTable[c.hashCode()%10] = c;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are Collisions

A

Anytime you use a hash formula to generate index positions, you could end up with the same index position for several values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How are collisions handled?

A

Collisions are handled by putting all the values with the same hash code in a list and storing the list at the index position the matches the hash code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Bucket Hashing/Chaining?

A

Using a bucket or a chan is a common way to describe putting all of the values with the same hash code in one list.

Basically to handle collisions.

The larger the array the less likely you are to have collisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Could you also use ListNode as LinkedLists in HashTables?

A

Yes, you could as they work well to chain items together.

ex) ListNode[] table = new ListNode[100];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly