{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

fall03finalexsol

fall03finalexsol - 1.00/1.001 Introduction to Computers and...

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

View Full Document Right Arrow Icon
1.00/1.001 Introduction to Computers and Engineering Problem Solving Final Examination - December 15, 2003 Name: TA: Section: E-mail Address: You have 3 hours to complete this exam. For coding questions, you do not need to include comments, and you should assume that all necessary files have already been imported. Good luck! Question Points Question 1 / 10 Question 2 / 10 Question 3 / 20 Question 4 / 60 Total / 100 1 / 15
Image of page 1

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

View Full Document Right Arrow Icon
Question 1. True or False (10 points) Answer the following questions about Java by circling TRUE or FALSE as appropriate. 1) If a and b are two references of the same type, then a. equals( b) will return true if and only if a and b refer to the same object. TRUE FALSE 2) Collisions will never occur in a hash table that uses chaining. TRUE FALSE 3) Java streams are Last In, First Out stacks. TRUE FALSE 4) It is not possible to read and write one file using the same stream. TRUE FALSE 5) An inorder traversal will visit the nodes in a binary search tree in increasing order. TRUE FALSE 2 / 15
Image of page 2
Question 2. Conceptual Question (10 points) There are situations or specific sets of data that can make an efficient algorithm or data structure give atypically inefficient or incorrect performance. Please describe at least two examples and strategies to remedy the problem in both cases. Example 1: A standard binary search tree will degenerate into a linked list if a sorted set of keys is inserted in order. This means that the tree’s normal insertion and retrieval time of O(log n) will worsen to that of a linked list, O(n). The solution us ed by most tree data structures in production algorithms is to rebalance the tree after certain operations if it starts to become unbalanced. Example 2: If simple quicksort uses the first or last element of the current array as the pivot and the sort is run on already sorted data, then one of the resulting subarrays will always contain only one element, and the efficiency of the sort will decrease from O(n lg n ) to O( n^2 ). Perversely, insertion sort, which usually runs in O( n^2 ), will run in O( n ) on presorted data, so insertion sort will actually run faster than quicksort in this case. The best approach to solving the problem is to choose the pivot more carefully. If the pivot is chosen as the median value of the first, last, and middle value of the array to be sorted, quicksort will maintain its O( n log n ) performance on all normal data. Example 3: If a hash map inserts keys which turn out to hash to the same slot or small set of slots, the performance on insertions and retrievals can decrease to O( n ) like a linked list rather than the normal O( 1 ). The solution is to use a better hash code method in the key class or if there is some periodicity in the key’s hash code that matches the number of cells in the hash map, to use a more sophisticated mapping of hash codes than taking the modulus. Making the hash function rehash the integer hash codes may help.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ 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