Fall 07 CS 100 Test 2 Solutions

Fall 07 CS 100 Test 2 Solutions - DUKE UNIVERSITY...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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 worst-case big-Oh 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 worst-case big-Oh 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. True PROBLEM 2 : ( Reverse (9 points) ) Each of the Java functions on the left take a string s as input, and returns its reverse. For each of the following, state the recurrence (if applicable) and give the big-Oh complexity bound.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '06
  • Astrachan
  • Computer Science, Adam Abby Adam Alex Anna Cole Dave Ella Emma Eric Erik Erin Evan Luke Kyle Owen Seth Jada Mary Hart Mark Joey Sean Noah Adam Dave Erik Erin Evan Jack Jada Jane Jeff Mary Noah Sean Luke Kyle Owen Seth Cole Alex Hart Mark Joey Emma Ella Abby Adam Alex Anna , Erik Erin Evan, Josh Jake Sara, Kyle Owen Seth

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern