This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: DUKE UNIVERSITY Department of Computer Science Test 2 Solutions: CompSci 100 PROBLEM 1 : ( Short ones (14 points) ) 1. You are creating a boggle word search program and you want to find all valid words where the letters are adjacent. What data structure would be best suited to hold the dictionary (i.e. lexicon)? Trie 2. In order to use the class Point containing fields x and y in a HashSet, you are considering multiple hash functions. Of these hash functions, which one would give the best performance in a HashSet ? Assume that your points are likely to be between (0, 0) and (1280, 1024) (the size of the average computer monitor). public int hashCode () { return x * 1000 + y; } 3. True or False State whether the following statement is true or false. If false, you should give a specific counterexample. I. A certain hash table contains N integer keys, all distinct, and each of its buckets contains at most K elements. Collisions are resolved using chaining. Assuming that the hashing function and the equality test require constant time, the time required to find all keys in the hash table that are between L and U is O ( K × ( U L )) in the worst case. True II. Instead of using a heap, we use an AVL tree to represent a priority queue. The worstcase bigOh of add ( insert ) and poll ( deleteMin ) do not change. True III. Instead of using a heap, we use a sorted ArrayList to represent a priority queue. The worstcase bigOh of add and poll do not change. False, adding is O ( n ) IV. Given the preorder and postorder traversals of a binary tree (i.e. printing out all of the elements but not the null nodes), it is possible to reconstruct the original tree. False, consider the a root with one child. Neither traversal will tell you whether it is a left or right child. V. Given the preorder and inorder traversals of a binary tree, it is possible to reconstruct the original tree....
View
Full
Document
This note was uploaded on 04/27/2008 for the course COMPSCI 100 taught by Professor Astrachan during the Fall '06 term at Duke.
 Fall '06
 Astrachan
 Computer Science

Click to edit the document details