CISC 320 Algorithms and Advanced Programming

Homework set #2, Fall, 2006

Due Wed, Oct. 11.

Five exercises on dynamic data sets.
  1. Exercise 6.2 from BG (our textbook), parts b and d. BG speak in terms of a stack implemented using a dynamic array. In class we spoke in terms of the STL vector implementation of dyanamic arrays and restricting attention to the the push_back() and pop_back() functions.. You may use either terminology. In either case, use t to denote the cost of moving one element from an old memory block to a new one, when memory is reallocated. Regarding part a, we found that this strategy can thrash and does not have constant amortized time. Regarding part c, we found that an amortized cost of 2t per push_back or pop_back would suffice (not counting the cost in a push_back of putting the new element in the array). In your answer for b and d, regarding the question "Which scheme offers the lowest constant factor" include consideration of the factor of 2 for part c.

  2. Exercise 6.4 from BG.

  3. Exercise 6.8 from BG. You may use dict in ~saunders/320/redblack/ on the composers. In that case, use the 10 keys 'a', 'b', ..., 'i', since the keys for that program are chars, not numbers. This makes the exercise very easy. To make it a useful exercise, try to predict before each insertion how the tree will look after the insertion.

  4. Exercise 6.9 from BG. You may use dict to assist in finding the solution.

  5. Write a traversal function for 2,3,4 trees that visits (and prints) the objects in sorted order. A template for this will be provided. Note: a recursive definition is considerably easier than an iterative one (which will need an auxiliary stack).