Practice Assignment 6 - Hash Tables | CSC 354, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: Data Structures; Subject: Computer Science; University: La Salle University; Term: Fall 2001;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-2rg-1
koofers-user-2rg-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment 6 - Hash Tables
CSC 354 Given: November 13, 2001
Value: 20 points Due: November 20, 2001
This is a pencil-and-paper assignment.
Objective: understand
·separate chaining and open addressing strategies
·collision resolution for open addressing by linear probing, quadratic probing, and
double hashing
Format
The assignment follows the pattern from class. Given a set of keys to be inserted into a
hash table, your task is to create a hash table first by separate chaining, then by open
addressing. For open addressing:
do the hashing 3 separate times, once with each of the following collision resolution
policies: linear probing, quadratic probing, and double hashing.
if a collision occurs, show the calculations you used to get the probe sequence, as
done in class. IF any mistakes occur, we can view the calculations to find the source
of the mistake.
You can choose the format most comfortable for you. Tables similar to those used in
class are given below. You can compute the appropriate hash values and add them, in
pencil, on the sheets below, or electronically in the Word document (f:\data\turk\csc354\
c354asn6-f01.doc). Alternatively, you can use a spreadsheet to display the hash tables.
Please double check that you are using the given key and in the correct order. You
will lose credit for using an incorrect key and/or order.
Exercise 1 - Separate Chaining
Assume:
·tablesize m = 5
·h(key) = key mod m, which is equivalent to: key % m so slot numbers are 0..4
·insertion is to the front of a list
Keys to be inserted are:
150, 60, 131, 260, 77, 187, 73, 354, 112, 17, 249, 148, 94
Exercise 2 - Open Addressing
Assume:
·tablesize m = 17
·h(key) = key mod m, which is equivalent to: key % m so slot numbers are 0..16
·for double hashing, r = 11, so h2 = 1 + (key mod r)
Keys to be inserted are:
150, 60, 131, 260, 77, 187, 73, 354, 112, 17, 249, 148, 94
CSC 354 1 Fall 2001
pf3
pf4
pf5

Partial preview of the text

Download Practice Assignment 6 - Hash Tables | CSC 354 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Assignment 6 - Hash Tables

CSC 354 Given: November 13, 2001 Value: 20 points Due: November 20, 2001 This is a pencil-and-paper assignment. Objective: understand · separate chaining and open addressing strategies · collision resolution for open addressing by linear probing, quadratic probing, and double hashing Format The assignment follows the pattern from class. Given a set of keys to be inserted into a hash table, your task is to create a hash table first by separate chaining, then by open addressing. For open addressing:  do the hashing 3 separate times, once with each of the following collision resolution policies: linear probing, quadratic probing, and double hashing.  if a collision occurs, show the calculations you used to get the probe sequence, as done in class. IF any mistakes occur, we can view the calculations to find the source of the mistake. You can choose the format most comfortable for you. Tables similar to those used in class are given below. You can compute the appropriate hash values and add them, in pencil, on the sheets below, or electronically in the Word document (f:\data\turk\csc354
c354asn6-f01.doc). Alternatively, you can use a spreadsheet to display the hash tables. Please double check that you are using the given key and in the correct order. You will lose credit for using an incorrect key and/or order. Exercise 1 - Separate Chaining Assume: · tablesize m = 5 · h(key) = key mod m, which is equivalent to: key % m so slot numbers are 0.. · insertion is to the front of a list Keys to be inserted are: 150, 60, 131, 260, 77, 187, 73, 354, 112, 17, 249, 148, 94 Exercise 2 - Open Addressing Assume: · tablesize m = 17 · h(key) = key mod m, which is equivalent to: key % m so slot numbers are 0.. · for double hashing, r = 11, so h 2 = 1 + (key mod r) Keys to be inserted are: 150, 60, 131, 260, 77, 187, 73, 354, 112, 17, 249, 148, 94

Exercises 3 and 4 differ from exercises 1 and 2 in the fields used in the hash functions. The rule is that the key field k is transformed, if necessary, to an integer, and this integer is then hashed. For simplicity here, the key field (the full name of the signer) is NOT used in this example. Definitions: for separate chaining: tablesize m is 7 h(k) = (day of death - 1) % 7 (subtracting 1 enables indices beginning with 0) insertion is to the front of the list for open addressing: tablesize m is 31 h(k) = day of death - 1 for double hashing, h 2 (k) = month of death NAME ( key ) DATE OF DEATH J. Adams July 4, 1826 S. Adams October 2, 1803 J. Bartlett May 19, 1795 C. Braxton October 10, 1797 C. Carroll November 14, 1832 S. Chase June 19, 1811 A. Clark September 15, 1794 G. Clymer January 23, 1813 W. Ellery February 15, 1820 W. Floyd August 4, 1821 B. Franklin April 17, 1790 E. Gerry November 23, 1814 B. Gwinnett May 19, 1777 L. Hall October 19, 1790 J. Hancock October 8, 1793 B. Harrison April 24, 1791 J. Hart May 11, 1779 J. Hewes November 10, 1779 T. Heyward March 6, 1809 W. Hooper October 14, 1790 In alphabetical order, names of the first twenty signers of the Declaration of Independence, and their death dates. Source: The World Almanac 1987 , page 442.

Exercise 2

OPEN ADDRESSING with COLLISION RESOLUTION BY

Linear Probing Quadratic Probing Double Hashing 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 values to be added: 150 60 131 260 77 187 73 354 112 17 249 148 94

HASHING BY SEPARATE CHAINING - Exercise 3

Add a new value to the front of the list. 0 o 1 o 2 o 3 o 4 o 5 o 6 o Values to be added: signers in the order given on page 2 of assignment.