Chapter 37 - Hash tables Flashcards

1
Q

Why are hash tables useful?

A

» Can quickly access data without having to look at all the records

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

What does a hashing algorithm do?

A

» Divide the key by the number of available address and take the remainder as the address

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

What happens when there is a synonym?

A

» When 2 pieces of data hash to the same address, this cause a collision

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

What is the simplest way of dealing with a collision?

A

» Is to store the item in the next available space, assuming it is free

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

What is a hash table?

A

» Abstract data structure where data is stored in an array format and enables access to structures that are not stored in a structured manner

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

What is the purpose of a hash function?

A

» Generates an address in a table for the data that can calculate the position of an item in the table

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

What is a collision?

A

» When a hashing algorithm maps 2 different keys to the same table address

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

What is the mid-square method?

A

» Square the item
» Extract the middle 2 digits
» Mod the value by the table size to get an address

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

What is the folding method?

A

» Divides the item into equal parts
» Add the pieces together
» Mod the value by the table size to get an address

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

What is a dictionary?

A

» An abstract data type composed of a collection of pairs such that each possible key appears at most once in the collection

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

How is it possible to hash a string?

A

» By using the ASCII code for each character
» Add the ASCII value for each character
» MOD the value by the table size

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

What are the consequences of having a fuller hash table?

A

» More likely it is that there will be collision

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

What is rehashing?

A

» Name given to the process of finding an empty slot when a collision has occurred
» Finding an alternative position for items in the hash table

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

What does each pair consist of in a dictionary?

A

» Key
» Value

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

What are the 3 good features of a hashing function?

A

» Be calculated quickly
» Result in as few collisions as possible
» Use as little memory as possible

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

What is linear probing?

A

» To find the item later that has been moved due to a collision
» The hashing function delivers the start position from which a linear search can then be applied until the item is found

17
Q

What is the disadvantage of linear probing?

A

» It prevents other items from being stored at their correct location in the hash table

18
Q

What is clustering?

A

» Several positions being filled around the common collision values

19
Q

What is the trade off in a hashing algorithm?

A

» Between the efficiency of the algorithm and the size of the hash table

20
Q

What is an alternative method of handling collisions ?

Hint - uses a dimensional array

A

» Uses 2D array

21
Q

What is chaining?

A

» The possibility of more than one item to be placed at the same position

22
Q

What is the purpose of an overflow table?

A

» Store the collisions in which items can be searched sequentially

23
Q

What are the common situations in which has tables can be used?

A

» File systems linking a file name
» Identifying the keywords in a programming language

24
Q

What are the 3 operations that are possible on a has table?

A

» Add
» Delete
» Retrieve - retrieves an item using its hash value

25
Q

What are the steps to add an item to a hash table?

A

» Calculate position of the item using a hashing function
» If the calculated position is empty, insert the item and stop

26
Q

What happens if the calculated position is not empty?

A

» Check the first position in the overflow table
» If position is empty, insert the item and stop
» Increment the position to check in the overflow table
» Repeat until item is inserted or the overflow table is found to be full

27
Q

What are the steps to remove an item from a hash table?

A

» Calculate position of the item using a hashing function
» If the calculated position contains the item to be deleted, delete it and stop

28
Q

What happens if the calculated position does not contain the item to be deleted?

A

» Check the first position in the overflow table
» If the position contains the item to be deleted, delete it and stop
» Increment position to check in the overflow table
» Repeat until the item is discovered, or the end of the overflow table is reached

29
Q

How can we traverse a hash table?

A

» It is very similar to how you add/ delete an item to a hash table