• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/22

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

22 Cards in this Set

  • Front
  • Back
What are the two different types of hash tables?
Chained hash table
Open address hash table
What is a hash table?
Its a data structure. An array.
What is a hash function?
A way to convert data into an integer. This number is then the location in the hash table.
What is a key?
The thing you convert into an integer.
Why use an array?
It provides fast random access.
What is a collision?
When some names lead to the same hash.
Problems with hash function?
Duplicates are inevitable,
Needs to produce an even spread of results.
How big do the different types of tables need to be?
Chained- same size as amount of data.
Open address- Twice the size as the amount of data.
What is a chained hash table?
Each location is the head of a chain,
Each location is a linked list.
Keys mapped to the same location are appended to the chain.
Retrieval means the chain must be searched and data removed.
Each location is like a bucket.
Advantages of a chained hash table?
Performance degrades gracefully.
Array size can be smaller than the number of data items.
Disadvantages of a chained hash table?
Retrieval can be slow due to the linked list needing to be traversed.
Efficiency decreased if the load factor is too high.
Efficiency decreases the more the hash function deviates from perfect hashing.
Worst case all the keys hash to the same bucket. Loses all the advantages of an array.
What is load factor?
number of entries/size
2 or 3 is acceptable
What is an open addressed hash table?
All the keys are stored in the table. Collisions resolved by probing- a process in which we search through locations to find an empty location in which to store the data.
What are the different types of probing?
Linear, double hashing and quadratic
How does linear probing work?
Look in array indexed by hash
If empty insert
If not empty try next cell along
Repeat until an empty cell is found.
use interval of 1
Problems with linear probing
Primary clustering
if a cluster forms then need to probe
Clustering leads to more probes
Operation slows down.
How does quadratic probing work?
Same as linear probing but makes increasingly large jumps through the array.
The sequence is the square of the number of tries so far attempted 1,4,9,16,25 etc
Problems with quadratic probing
The array must be a prime number
Overcomes primary clustering but suffers with secondary clustering
Keys with the same hash follow same probe sequence.
How does double hashing work?
Employs a second hashing function.
Need to ensure that probing visits every cell before visiting any cell twice.
Size of the table should be a prime or a power of 2
What is the problem with deletion in a open address table
If 2 keys have the same hash then probing must be used to store the second key. If the first item is deleted then unable to find the second.
Need to put a senital in to mark a location as used but empty.
Advantages of an open addressed hash table
Easy to implement
Disadvantages of an open address hash table
Doesnt cope well with lots of deletions.
Worse case is the table gets to full and then the hash is not in the table.
Full tables are bad- shouldnt be more than 80% full