test1sol - Name Student ID Department of Electrical and...

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

View Full Document Right Arrow Icon
Name: Student ID: Department of Electrical and Computer Engineering Computer Engineering ECSE 322 CLASS TEST 1 - Solutions October 4, 2010 – 12:35 to 13:25 This is a closed book test. No aids other than a hand calculator are permitted. All questions carry an equal weight and each is worth 6 marks. All questions must be answered on this sheet - no other answer books will be marked. DO NOT FORGET TO WRITE YOUR NAME AND STUDENT ID ON EVERY PAGE OF THIS QUESTION SHEET. 1. (a) Explain the following terms in your own words (2 marks). (i) “bucket hashing” Each slot in the hash array has associated with it a linear array, known as a “bucket”. In the event that a second item arrives to be stored in an already occupied slot, it is placed in the associated bucket storage area. Items are entered in the bucket in a linear manner, i.e. the first item is in the first position, the second in the second, etc. (ii) “stack” (b) Assume that you are hashing key K to a hash table of n slots (indexed from 0 to n-1). For each of the following functions h(K), is the function acceptable as a hash function (i.e., would the hash program work correctly for both insertions and searches), and, if so, is it a good hash function? Function random(n) returns a random integer between 0 and n- 1 inclusive. (0.5 marks for (i) and 0.5 marks for (ii)) (i) h(K) = 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Name: Student ID: 2 This hashes all the input data to the same location. As such, it will lead to n collisions if n data items are received. A set of hash functions will be needed to allow for rehashing on all but the first data item. This is not a good function. It is likely to be extremely slow for both insertion and searching. (ii) h(K) = (K + random(n)) mod n The use of a random number to implement a hashing function is not a good idea because there is no guarantee that it will access all the possible slots in the hashed array. There could be a large number of collisions. In terms of searching for a data item, it is particularly bad since the function random(n) will not necessarily run through the same sequence of results each time it is used. Hence an attempt to search for an item will not follow the same set of events as the storage of an element would have done. (c) We need to use a hashing function in order to store, in an array of strings, family names of the 10 top students of a class of 1000 students. We have the following family of hashing functions: H k (e) = ((e)ModM+k)Mod M, where k is the hashing function number, and M is the number of positions in the array. (i)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/22/2010 for the course ECSE ECSE 322 taught by Professor Lowther during the Winter '04 term at McGill.

Page1 / 11

test1sol - Name Student ID Department of Electrical and...

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

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