Sample Questions for Final Exam CSCI 1902, Fall 2006 This is a set of sample questions for the final exam. It is intended to give you a sense of what type of questions to expect on the exam. It also illustrates the different "levels of knowledge" of exam questions. There are several things this set of questions is *not*. (1) It is not a comprehensive list of the topics that may be covered. The best source for that is the lecture notes and the review concepts document. (2) It is not a sample final: the time required to complete the questions below is not the same as that required to complete the final, and the distribution of questions is not the same. (3) It is not (syntactically speaking) an example of a successful "Exam Question Proposal"; it contains more questions than necessary and no answers. ============================================================ KNOWLEDGE Are these structures Binary Search Trees? 1. 55 2. 55 / \ 12 67 3. 55 / \ 32 48 4. 55 / \ 32 66 / \ / \ 12 33 50 77 ============================================================ COMPREHENSION & APPLICATION You are working on setting up a student database, and you need to store a set of students in memory for a short time. A colleague suggests a Hashtable, since it is fast and easy to code. As the hash function, the colleague suggests that you use the length in characters of each student's last name. Is this a good hash function? Explain your answer. How about each student's ID? Explain your answer. ========== Demonstrate the insertion of the keys 5, 28, 19, 15, 20, 33, 12, 17, 10 into a hash table with collisions resolved by chaining. Let the table have 9 slots and let the hash function be h(x)=x mod 9 ============================================================ PROBLEM SOLVING Suppose we have numbers between 1 and 1000 in a binary search tree and want to search for the number 363. which of the following sequences could not be the sequence of nodes examined? A. 2, 252, 401, 398, 330, 344, 397, 363, B. 924, 220, 911, 244, 898, 258, 362, 363 C. 925, 202, 911, 240, 912, 245, 363, D. 2, 399, 387, 219, 266, 382, 381, 278, 363 E. 935, 278, 347, 621, 299, 392, 358, 363. ========== Consider the data structure known as a Trie, used for storing sets of words. It is a tree structure, but instead of binary, it is 26-ary. That is, each node has 26 children. Each child corresponds to a letter of the alphabet. The data structure starts with the root node, then for each letter in a word, travels along that specific letter's child pointer. Each node also stores a boolean, which is true if the sequence of letters ending in that node is a word, false otherwise. Show a trie that contains the keys "to", "tom", "torn", "tin", "in", and "inn". Suppose you were to use this structure to implement Set. What would the Big-O time of add() be? How about contains? Could this structure be adapted to support the Dictionary ADT? If so, how, and in what circumstances? If not, why not? ========== Consider a priority queue (of integers, where the integers themselves are the priorities) after the following sequence of operations: enqueue(8) enqueue(5) enqueue(15) enqueue(20) enqueue(10) dequeue() dequeue() dequeue() A. Show what the priortity queue would look like after this sequence of operations.