Homework Assignment

List and Sequence ADTs

Contents:

  • Overview
  • Practice Problems
  • Problems to be Submitted
  • Extra Credit

  • Overview

    Topic: List and Sequence ADT
    Related Reading: Ch. 5.2-5.3 and 5.5-5.6
    Due:

    Please make sure you adhere to the policies on academic honesty.


    Practice Problems

  • Reinforcement Exercise R-5.2.
  • Reinforcement Exercise R-5.6.

  • Problems to be Submitted (20 points)

    1. (7 points)
      Let MySequence be a sequence of 99 Dalmation puppies, and let Boiler be a Dalmation puppy. Give the value returned or the exception thrown by each of the following statements that make calls to the methods of the MySequence object:
      1. size()
      2. isempty()
      3. rankOf(first())
      4. rankOf(last())
      5. rankOf(atRank(0))
      6. rankOf(atRank(99))
      7. rankOf(atRank(100))
      8. rankOf(atRank(size()))
      9. rankOf(before(last()))
      10. rankOf(after(before(first())))
      11. rankOf(insertFirst(Boiler))
      12. rankOf(insertBefore(first(),Boiler))
      13. remove(first())
      14. remove(insertAtRank(1,Boiler))

      Please Note: There is an error in many printings of the book in Ch. 5.2.3, when desribing the List ADT. That section states that the method insertBefore(p,e) throws an error if p is the first position. There is no reason to throw such an error, as that statement has a natural meaning. In fact, if you look at Code Fragment 5.9, you will see that they have implemented it properly. A similar correction should be made regarding insertAfter(p,e).

    2. (5 points)
      Using the List interface methods, give a short fragment of pseudo-code describing a new method makeFirst(p) that moves the element of a list L at position p to be the first element in L while keeping the relative ordering of the remaining elements in L unchanged. Your method should only call O(1) other List methods.

    3. (8 points)
      Creativity Exercise C-5.11 of the text.

    Extra Credit

    1. (2 points)
      Creativity Exercise C-5.12 of the text.
      (Hint available through Hint Server on textbook's website).


    Last modified: 1 October 2002