12.07.2015 Views

CS220 Exam 2 Short Answers:

CS220 Exam 2 Short Answers:

CS220 Exam 2 Short Answers:

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>CS220</strong> <strong>Exam</strong> 2Answer: cAnswer: c.Answer: c.Answer: dAnswer: c.Answer: a.Answer: a.Answer: b.Answer: c.Answer: c.Answer: dAnswer: a.Answer: b.Answer: c.Answer: b.Answer: d<strong>Short</strong> <strong>Answers</strong>:1) What is the drawback of the mergesort with respect to storage? Compare the efficiencies of thequicksort and the mergesort in the worst case. ( 5 points)Answer: The mergesort requires an auxiliary array whose size equals the size of the original array. Forlanguages, such as C++, which store the data items in the array, this requirement might not be acceptable insituations where storage is limited.Answer: In the worst case, the quicksort is significantly slower than the mergesort. In the worst case, thequicksort is O(n 2 ), while the mergesort is O(n * log 2 n).2) What is the effect of the assumption that all items in a table have distinct search keys, on theinsertion operation of a dictionary?( 5 points)Answer: Under this assumption, the insertion operation must reject or update an attempt to insert an itemwhose search key is the same as an item already in the table. Search must be done to determine whether ornot duplicate exists.3) What is a perfect hash function? What is the desired property of hash table size and why? Hint:Explain it based on hash code compression equation: hash index = hash code % table size. ( 5points)Answer: It is an ideal hash function that maps each search key into a unique location in the hash table.Prime number for hash table size. Same parity of hash index and hash code if table size is even.4) What is the potential problem associated with open addressing technique? Hint: from the aspect ofthree kinds of entries, namely Available, Empty and Occupied after frequent addition and removal.(5 points)Answer: Frequent addition and removals can cause every location in the hash table to reference either acurrent entry or a former entry. That is no location that contains null.If this happens, our approach to search a probe sequence will not work. Unsuccessful search should end atnull, this case it has to search all locations.5) Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x mod 10,show the resulting ( 8 points):a. Separate chaining hash tableb. Hash table using linear probingc. Hash table using quadratic probingd. Hash table with second hash function h2(x) = 7 – x mod 7a.01 4371


23 1323 61734 434456789 4199 9679 1989b.0 96791 43712 19893 13234 61735 43446789 4199c0 96791 437123 13234 61735 4344678 19899 4199d01 437123 13234 61735 967967 434489 4199Bonus6) What is meant by clustering in hashing? Discuss three open addressing techniques including linearprobe, quadratic probe and double hashing from the aspect of clustering problems they mightcause. How does clustering affect the overall efficiency of hashing? ( 5 points)Answer: Clustering is the tendency of items to map into groups of locations in a hash table, rather thanrandomly scattered locations. Linear: primary clustering, quadratic: secondary clustering, doublehashing avoids clustering problem. Clustering can cause lengthy search times and therefore decreasethe overall efficiency of hashing.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!