Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Hash Tables: Primary & Secondary Clustering and Collision Resolution - Prof., Assignments of Computer Science

The concepts of primary and secondary clustering in hash tables and explains different collision resolution schemes, including linear probing, quadratic probing, and double hashing. It also provides examples of inappropriate hash functions and shows the resulting hash table for a given set of integers using linear probing, quadratic probing, double hashing, and chaining.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-ao2
koofers-user-ao2 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Understanding Hash Tables: Primary & Secondary Clustering and Collision Resolution - Prof. and more Assignments Computer Science in PDF only on Docsity! Written 3 Page 1 CS 2420 – Written 3 10 Points Due September 26, 2008 1. The definitions of primary and secondary clustering are sometimes difficult to get straight. In primary clustering, not only do items collide because they hash to the same location, but one item may collide with the alternate location for another. This occurs in linear probing. When the item that hashes to x is placed in y, items that hash to either x or y both try the same next location. In secondary clustering, two items that hash to the same location follow the same probe sequence for subsequent locations. This happens in quadratic probing. Only items that hash to location x continue to try the same sequence of alternate locations. If something has primary clustering, it will also have secondary clustering. If a hash method does not exhibit primary or secondary clustering, it is termed non-clustering. This happens with double hashing. Even items which hash to the same location do not continue to try the same sequence of alternate locations because each is using a different step value. Notice that non-clustering methods are the best, and methods that exhibit primary clustering are the worst. Consider the following collision resolution schemes. Indicate whether they are non-clustering, secondary clustering, or primary clustering. a. You use linear probing, but always increment by 3 (rather than 1) in the event of a collision. b. You have 10 completely different hash functions. If the first method produces a collision, you try the second, and so on until you find a spot or until all hash functions are exhausted. At that point, the hash fails and you will need to rehash. c. You have an overflow area at the bottom of the table. Instead of using open addressing (placing items that won’t fit in the computed address in an open space), you put all items that won’t fit in the computed address in this overflow area (sequentially). 2. A hash function is appropriate if it is (a) fast to compute, (b) minimizes collisions, (c) is repeatable, and (d) produces values between 0 and the size of the table. All of the following hash functions are inappropriate. Explain why. (Note, when we say a function minimizes collisions, we are saying, that for a reasonable number of typical data items, the number of collisions is not great. Anything can be forced to collide if you use too much data for the table or pick atypical data items.) a. The hash table has a size of 2,047. The search keys are identifier names in C++. The hash function is h(key) = (position of the first letter of key in alphabet) % size. b. The hash table is 1000 entries long. The search keys are integers between 0 and 9999. The hash function is h(key) = (key*random()) % tablesize where random() is a sophisticated random-number generator that returns a real value between 0 and 1. c. The hash table is 10,007 entries long. The search keys are integers between 0 and 9999. The hash function is given by const int TABLESIZE = 10007; int Hash(int X)
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved