CS140 -- Lab 9 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 using:

    1. separate chaining -- 5
    2. quadratic probing -- 7

  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: Phil Fulmer
      1: Pat Summitt  (hashes to 0 and quadratic probing with i=1 puts her here)
      2: empty
      3: empty
      4: Cutcliffe (hashes to 0 and quadratic probing with i=2 puts him here)
      5: empty
      6: Rod Delmonico
      
      Phil Fulmer, Pat Summitt, and Cutcliffe collide since they all hash to 0. They appear in that order in scfile1, so Phil Fulmer ends up in location 0. Pat Summitt is inserted next and is placed in location 0 + 12 = 1. Finally Cutcliffe is inserted and is placed in location 0 + 22 = 4.

  4. 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;
    

  5. 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

  6. Write a test program called hash_test.c that performs the following actions:

    1. inserts character strings read from the command line into your hash table.
    2. performs a find on each string in argv and prints out a string if it is not found. The only string not found will be argv[0], which is the name of your executable.
    3. prints the hash table size and contents using hash_print_table
    hash_test.c