Hashing-Practice

Hashing-Practice - 15-121: Introduction to Data Structures...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-121: Introduction to Data Structures Exercise 10/15/2009 Relevant Reading: • Chapter 14 in the Lewis and Chase book. Hashing Practice Fall 2009 Due: none Assignment: (worth 0 exercise points - this is for practice only) Consider the following potential hashCode functions for Strings. public int hashCode() { if (length() == 0) return 1; return length() + UnicodeValueOf (charAt(0)); } public int hashCode() { int sum = 0; for (int i = 0; i < length(); i++) sum += i * UnicodeValueOf (charAt(i)); return sum; } Below is a list of words. Insert the list of words IN ORDER, one at a time into a hash table. Use both functions, two different table sizes (10 and 25) and both chaining (another word for bucketing) and probing. Thus, you need to create 8 tables. • • • • • • • • HashCode function on the left, Chaining for collisions, 10 cells in the array. HashCode function on the left, Chaining for collisions, 25 cells in the array. HashCode function on the left, linear probing for collisions, 10 cells in the array. HashCode function on the left, linear probing for collisions, 25 cells in the array. HashCode function on the right, Chaining for collisions, 10 cells in the array. HashCode function on the right, Chaining for collisions, 25 cells in the array. HashCode function on the right, linear probing for collisions, 10 cells in the array. HashCode function on the right, linear probing for collisions, 25 cells in the array. Show a picture of each resulting table. For each table, simulate a search for each of the words in the second list below. For each key, indicate how many words you have to check to find out if the search key is in the table or not. Does the table grow as it becomes full? Try simulating both ways (growing and not growing). Handin: • Nothing to hand in. Words to be inserted: cat dog pig frog bird alligator cow bobcat hen wren crow tiger lion deer camel Words to be searched: hen cat cow bobcat crocodile jay deer ...
View Full Document

This document was uploaded on 12/19/2009.

Page1 / 2

Hashing-Practice - 15-121: Introduction to Data Structures...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online