Docsity

Practice Midterm Exam with Solutions - Computer Algorithms I | MCS 401, Exams of Algorithms and Programming

Partial preview of the text

Download Practice Midterm Exam with Solutions - Computer Algorithms I | MCS 401 and more Exams Algorithms and Programming in PDF only on Docsity!

none, Andon MCS 401 Midterm (Oct 24, 2008) (1) (a) Consider inserting the keys 10,4, 11,24, 2,16 into a hash table of length m = 7 using open addressing with the primary hash function h’(k}) = k modm. Complete the following table to illustrate the result of inserting these keys using linear probing and double hashing with hg(k) = 1+(k mod (m-~1)). Give the formulas for h(k,i) and indicate the numbers (values of i) of the successful probes in parentheses. method RE, 10 4 il | #4] 2] 16 Wk) = 3 4 q{[ 62722 linear probing [hitk}+c)med mm} 300) 4@) | 5) F673) | 2(0)| OG) halk) = 5 5 & i 2 /F double hashing (h'(k)+ eh, Q)malm 3) 4(e)| 2(2) (SLi) feta read part (b) = olf Ol, 027 O27 02] 62 (b) The cost of retrieving an entry in the hash table is the number of probes needed to locate the slot with the corresponding key. For the given table the maximal cost for linear probing is| 4 | and for double hashing is % Assume that the probabilities of requests for the entries are as in the last row of the above table. What is the expected cost. of retrieving a random entry for linear probing? or C4 + o.2(Z2+ Ace te & = 2.2 * for double hashing? 0-1 (E41) + 0.2 (S434 34 2) = 2% (2) (a) Show how the radix sort operates on the following "deck” of numbers: 321 BE a2] 12% 246 G45 (24 a4b 654 12% $43 32 567 9 29D ny S43 wy 333 543 bo4 246 G45 1230 «246 bs4 S67 333 Sé6T S67 64 (by What does it mean for a sorting algorithm to be stable ? “Twe elements with the Sadie be apbeca oe the same order in the out fat, (c) Give a "Big O” bound on the running time Of the radix sort for an array of n nonnegative integers with at most d digits each using the counting sort as a subroutine. Explain what this bound follows from. D ( n) = 0 (4 (ns k)) , we eae ke ado (Sor deed yall discls ) The Counting Gort is exeouted a times , its Fiche ft me 1s O (n) wat D (- oe ky