Sample Questions for Quiz 4 CSCI 1902, Fall 2008 This is a set of sample questions for Quiz 4. 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 quiz: the set of questions below would take longer than 25 minutes to complete (3) It is not (syntactically speaking) an example of a successful "Quiz Question Proposal"; it contains more questions than necessary and no answers. ============================================================ KNOWLEDGE List three methods of the stack ADT. ========== List two methods for the queue ADT. ========== If you implement a stack with a linked list, what is the big-Oh efficiency of push? What is the big-Oh efficiency of pop? ============================================================ COMPREHENSION & APPLICATION What is the difference between a stack and a queue? ========== 3. Suppose s1 and s2 are two initially empty stacks. Draw what they look like after the following sequence of operations: s1.push(1); s1.push(2); S1.push(3); s2.push(s1.pop()); s2.push(s1.peek()); ========== The Map interface in Java has two generic type parameters. Explain the two parameters and write some example code to declare a Map variable. ============================================================ PROBLEM SOLVING Write code to reverse a linked list. ========== Given input data of the form , write code to create a map from average scores to the names of all student who achieved that score. ========== You are writing parts of a CSCI 1902 assignment, and you've written your Stack, and it works fine for all the implemented methods - push, pop, isEmpty, and clear. Now you're writing your Queue class, and you've gotten enqueue, dequeue and isEmpty working, but you are asked to write a reverse() method, that reverses the order of items in your Queue. You are all set to write a somewhat complicated method, when you realize that you can actually write the entire method in just a few simple lines, you don't even need to reference the private attributes of your queue class. How do you do it? ========== Consider using a queue to model the waiting list for a class. Give one reason this is a bad choice, and suggest an alternative ADT to use. Are there any drawbacks to the ADT you suggest?