CS 1723-001 Data Structures
Fall 2001 -- Review for Exam I

Sample Questions (New! NOTE: at 9:45 pm, I'm not adding any more answers. Good luck tomorrow.):

(Note: I will add material to this, including answers, on Tuesday, 16 October 2001. Notice that Exercise 3 has an answer at the bottom.)

  1. Using "wrapper" classes: ( Answer to both 1 and 2 Don't look at until you have tried the problem.)

      Start with a double double d = 47.5.

    1. Show how to wrap d so that we end up with a Double dWrap that contains the same number 47.5 inside.
    2. Show how to unwrap this class to get the value of the double that is inside back out.

  2. Using the Java Stack class: ( Answer to both 1 and 2 Don't look at until you have tried the problem.)

    1. Show how to create an instance of the Java Stack class.
    2. Show how to push the double above onto the stack in a,
    3. Show how to pop (remove) this stack element and then how to get the value of the double that was wrapped on the stack.

  3. Implementing stacks from scratch:

    In a separate class (perhaps called DoubleStack), allocate an array of doubles, and use an integer variable top to write methods pop, push, and empty that will implement a stack of doubles. (Don't do any error checking or checking for a full stack or an empty stack.)

  4. Implementing a stack of Comparables from scratch:

    1. Show where you would change the previous stack so that it would be a stack of items declared Comparable items.
    2. With this stack (perhaps called ComparableStack), what does it mean to say the stack implements Comparable?
    3. What were the circumstances in class under which we wanted the Comparable interface implemented?

  5. Strings: ( Answer Don't look at until you have tried the problem.)

    Using the charAt method of the String class, show how to decide if a string is a palindrome, that is, reads the same forwards as backwards, such as the famous words that Adam and Eve might have exchanged (with the blanks omitted): "madam im adam" and "name no one man", or Napolean's possible words (blanks can stay): "able was i ere i saw elba".

  6. Extending classes: ( Partial Answer Don't look at until you have tried the problem.)

    Consider a simple class hierarchy (adapted and simplified from your Weiss text), with classes Person, Employee, Student, and Persons: class hierarchy

    1. Write a new class Faculty with a new int data field courseLoad that gives the number of hours the faculty member is teaching. Show additions to the Persons class to add another person to the array: a new faculty member with name Warner, Joshua, ssn 563-55-5719, age 47, salary 53000, and course load 9.

    2. Suppose you want to add objects of type Person to a list of Comparable items, as we did in class. Suppose we then want to remove the objects in alphabetic order by name, using the removeMin method in the general CompList class we had before. What changes and additions are needed to the class hierarchy above? (Then this becomes a priority queue, where the priority is the alphabetic position of the name (people get preference who come early in the alphabet).)

    3. Suppose instead you wanted removeMin to remove in decreasing order of age. Show the changes to (b) above. (Here it is a priority queue, with age as the priority.)

  7. RPN: ( Answer Don't look at until you have tried the problem.)

      Consider the following arithmetic expression:
      
            3*5^(4-2)+6
         
    1. Use the method from class to translate this expression to RPN. (Do it step-by-step, using the stack and showing steps.)
    2. Use the method from class to evaluate the resulting RPN. (Again do it step-by-step, showing the use of a stack.)
Material presented in class that might be covered on the exam:

Projects and Exercises:

Recitations: See the List of Recitations.


Revision date: 2001-10-12. (Use ISO 8601, an International Standard.)