CS140 -- Lab 10 Design Answers

  1. Compute the value returned by the above hash function for each of the names in scfile1 and scfile2.
    
    hash("Pat Summitt") = 6
    hash("Cutcliffe") = 5
    hash("Rod Delmonico") = 2
    hash("Phil Fulmer") = 0
    

  2. Given the names in scfile1 and scfile2, what will be the size of your hash table: 5 -- 5 is the first prime number bigger than 4, which is the total number of unique names in the two score files

  3. Using the names in scfile1 and scfile2 draw the hash table that will result using:

    1. separate chaining
      0: empty
      1: Cutcliffe, Pat Summitt
      2: Phil Fulmer
      3: empty
      4: Rod Delmonico
      
    2. quadratic probing
      0: Empty
      1: Pat Summitt
      2: Phil Fulmer
      3: Cutcliffe (Cutcliffe hashes to 1 but collides with Pat Summitt)
      4: Rod Delmonico
      
      When Cutcliffe is inserted, Pat Summitt is already at location 1 so your algorithm starts moving linearly through the hash table. Phil Fulmer already occupies location 2 but location 3 is empty, so Cutcliffe ends up in location 3.

    3. Show the struct that you will declare to hold the information associated with a person. This struct will be passed as the value parameter to your hash table.

      
      typedef struct {
        double cumulative_score;
        int number_of_scores;
      } person;
      

    4. What error checks do you think your program should perform?

      1. Ensure that there are at least 3 command line arguments
      2. Ensure that the command line estimate of the number of unique names is a non-negative integer.
      3. Ensure that each file on the command line can be opened
      4. Ensure that each input line has at least two fields, one for a name and one for a score
      5. Ensure that the last field on each line is a non-negative number