CSE 373, Autumn 2002: Homework 2

Due 10/18/2002

For all program or data structure design problems such as the two below you must provide pseudocode (see the manual) and an adequate explanation of the methods. It is often helpful to include small examples demonstrating the methods. Straight pseudocode with no additional documentation is not enough.  Your pseudocode can contain English if needed.  Each problem should be answered on a separate sheets of paper so they can be graded by different TAs.  Your name should be at the top of every page.
  1. (10 points) A recursive version of Insertionsort works as follows.  We have a list to sort.  If the list is empty then there is nothing to do. Otherwise, sort all but the first element of the list recursively, then insert the first element of the list into its proper place in the the list by comparing it to members of the returned list which is already sorted.
  2. (10 points) Design an array based data structure for two stacks called a DualStack  The two stacks should share the same array in an efficient manner.  If there are MaxSize entries in the array then the IsFull function should only return true is all the entries in the array are occupied.  Your operations should all be constant time.
  3. 10 points) Consider the following general recurrence T(1) <= d and T(n) <= aT(n/b) + cn for a time bound. Show that:
  4. You may assume that n is a power of b in your argument. A very good argument would determine the constants and low order terms hidden in the big O notation, and show the bound by induction on n.