Skip to content

SiegerJman/05_Hashing_Lab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

05_Hashing_Lab

Implement a hash table in C++

Requirements

  1. keyExists, find, remove, and size should all be O(1)
  2. add should be reasonably fast. Use linear probing to find an open slot in the hash table. This will be O(1), on average, except when grow is called.
  3. grow should be O(n)
  4. Do not leak memory

Reading

"Open Data Structures," Chapter 5, except for 5.2.3. http://opendatastructures.org/ods-cpp/5_Hash_Tables.html

Questions

1. Which of the above requirements work, and which do not? For each requirement, write a brief response.

  1. all of those methods have run times of O(1).
  2. asdd linearly probes for a new space if needed.
  3. grow add each old term into the new array in O(n) time.
  4. memory is not leaked as data is manually deleted as it isnt needed anymore.

2. I decided to use two function (keyExists and find) to enable lookup of keys. Another option would have been to have find return a T*, which would be NULL if an item with matching key is not found. Which design do you think would be better? Explain your reasoning. You may notice that the designers of C++ made the same decision I did when they designed http://www.cplusplus.com/reference/unordered_map/unordered_map/

Splitting the method into two parts allows only a small portion of the method to have to be run every time. That part in this case being the keyExists function.

3. What is one question that confused you about this exercise, or one piece of advice you would share with students next semester?

About

Implement a hash table in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.0%
  • Objective-C 6.0%