CMPS-2020 Programming II: Data Structures and Algorithms
Lab-7

Overview:

Programming
Please do your work in your Odin 2020/7/ folder.

Name this program lab7.cpp

We will start this exercise together on the big screen.

1. Setup a class for a simple hash table.
   Start by declaring an array to hold simple integer values.
   Declare the important components we learned about in lecture.
   Start with a hash table size of 7.

2. Write a hash function.

3. Write an insert function.

4. Generate 5 values to insert into your hash table.
   This will cause your load-factor to rise to about 0.71.
   When load-factor is 0.7 or above, resize your hash table.

   When expanding your array...
      Use a multiply factor of 1.5, and round up.
      On your first resize, the new table size will be 11.
      On your second resize, the new table size will be 17.
      Still prime numbers!

      For homework, you should find the next-largest prime
      number to use for a table size.

5. Insert enough values into your hash table so that the size
   will be expanded twice.

   Include some values that will cause collisions if you can.
   You should thoroughly test your hash table functions while
   it is a simple integer array.

6. Write a search function.
   Send some test values to the search function.
   Verify the results.


Homework
Do your work on Odin in 2020/7/

and name this program hw7.cpp

Use your hash table knowledge to do the following...

1. Define a hash table class for character data.
   Your hash table will store character strings.

   Our lab-7 hash table held integers as keys.
   Your new hash table will hold character strings.

   You may use strings or c-strings.


2. A dictionary file is here:

   /usr/share/dict/cracklib-small

   Insert dictionary words into your hash table.

3. Prompt the user for the initial hash table size.
   Prompt the user for the length of words to insert into the table.

4. Your hash function will add up the ASCII values in a word and mod
   by the table size.
   
5. Write a main function that demonstrates your hash table.


Additional features...

Use linear probing to resolve collisions.

Use a resize factor of 2.
As you resize your table, make the new size is a prime number.


Sample output

Homework-7 Hash-table of words from the dictionary Initial table size: 3 Enter the length of English words to be hashed: 19 Creating hash table. hash table initial size: 3 Inserting words from the file: /usr/share/dict/cracklib-small resizeTable() new size:7 resizeTable() new size:17 hash table... 0 misrepresentation's 1 conceptualization's 2 -null- 3 -null- 4 -null- 5 -null- 6 anthropomorphically 7 -null- 8 -null- 9 interrelationship's 10 incomprehensibility 11 straightforwardness 12 -null- 13 -null- 14 -null- 15 -null- 16 -null- size: 17 n: 6 load factor: 0.352941 search for word: conceptualization's found at index: 1 in hash table. delete word: incomprehensibility notice: word deleted. hash table... 0 misrepresentation's 1 conceptualization's 2 -null- 3 -null- 4 -null- 5 -null- 6 anthropomorphically 7 -null- 8 -null- 9 interrelationship's 10 -deleted- 11 straightforwardness 12 -null- 13 -null- 14 -null- 15 -null- 16 -null- size: 17 n: 5 load factor: 0.294118
Write a function to list words at the start of the hash table array. Show size, n, and load-factor.

What to turn in...
Your work must be on Odin at...

2020/7/lab7.cpp   <--- lab, integer hash table

2020/7/hw7.cpp    <--- homework, string hash table