12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

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.

Sec. 9.7 Projects 355Be sure <strong>to</strong> indicate how you are using H1 <strong>and</strong> H2 <strong>to</strong> do the hashing. FunctionRev(k) reverses the decimal digits of k, for example, Rev(37) = 73;Rev(7) = 7.H1(k) = k mod 13.H2(k) = (Rev(k + 1) mod 11).Keys: 2, 8, 31, 20, 19, 18, 53, 27.9.19 Write an algorithm for a deletion function for hash tables that replaces therecord with a special value indicating a <strong>to</strong>mbs<strong>to</strong>ne. Modify the functionshashInsert <strong>and</strong> hashSearch <strong>to</strong> work correctly with <strong>to</strong>mbs<strong>to</strong>nes.9.20 Consider the following permutation for the numbers 1 <strong>to</strong> 6:2, 4, 6, 1, 3, 5.Analyze what will happen if this permutation is used by an implementation ofpseudo-r<strong>and</strong>om probing on a hash table of size seven. Will this permutationsolve the problem of primary clustering? What does this say about selectinga permutation for use when implementing pseudo-r<strong>and</strong>om probing?9.7 Projects9.1 Implement a binary search <strong>and</strong> the quadratic binary search of Section 9.1.Run your implementations over a large range of problem sizes, timing theresults for each algorithm. Graph <strong>and</strong> compare these timing results.9.2 Implement the three self-organizing list heuristics count, move-<strong>to</strong>-front, <strong>and</strong>transpose. Compare the cost for running the three heuristics on various inputdata. The cost metric should be the <strong>to</strong>tal number of comparisons requiredwhen searching the list. It is important <strong>to</strong> compare the heuristics using inputdata for which self-organizing lists are reasonable, that is, on frequency distributionsthat are uneven. One good approach is <strong>to</strong> read text files. The listshould s<strong>to</strong>re individual words in the text file. Begin with an empty list, aswas done for the text compression example of Section 9.2. Each time a wordis encountered in the text file, search for it in the self-organizing list. If theword is found, reorder the list as appropriate. If the word is not in the list,add it <strong>to</strong> the end of the list <strong>and</strong> then reorder as appropriate.9.3 Implement the text compression system described in Section 9.2.9.4 Implement a system for managing document retrieval. Your system shouldhave the ability <strong>to</strong> insert (abstract references <strong>to</strong>) documents in<strong>to</strong> the system,associate keywords with a given document, <strong>and</strong> <strong>to</strong> search for documents withspecified keywords.

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

Saved successfully!

Ooh no, something went wrong!