CSCE 221: Data Structures and Algorithms

Sections: 507, 508, 509
Fall 2015



Homework 2


Due Date: Sept. 11th (before class)


Assignment

  1. R6.4 (Pg. 262)

    Draw a representation of an initially empty vector A after performing the following sequence of operations: insert(0,4), insert(0,3), insert(0,2), insert(2,1), insert(1,5), insert(1,6), insert(3,7), insert(0,8).

  2. R6.19 (Pg. 263)

    Briefly describe how to perform a new sequence function makeFirst(p) that moves an element of a sequence S at position p to be the first element in S while keeping the relative ordering of the remaining elements in S unchanged. Your function should run in O(1) time if S is implemented with a doubly linked list.

  3. C6.5 (Pg. 264)

    Describe a function for performing a card shuffle of an array of 2n elements, by converting it into two lists. A card shuffle is a permutation where a list L is cut into two lists, L1 and L2, where L1 is the first half of L and L2 is the second half of L, and then these two lists are merged into one by taking the first element in L1, then the first element in L2, followed by the second element in L1, the second element in L2, and so on.

  4. C6.13 (Pg. 265)

    Describe an efficient way of putting a vector representing a deck of n cards into random order. You may use a function, randomInteger(n), which returns a random number between 0 and n - 1, inclusive. Your method should guarantee that every possible ordering is equally likely. What is the running time of your function?


Bonus

    C6.15 (Pg. 265)

    An array is sparse if most of its entries are NULL. A list L can be used to implement such an array, A, efficiently. In particular, for each nonnull cell A[i], we can store an entry (i,e) in L, where e is the element stored at A[i]. This approach allows us to represent A using O(m) storage, where m is the number of nonnull entries in A. Describe and analyze efficient ways of performing the functions of the vector ADT on such a representation.


Grading Rubric

Each homework composes 2% of your final grade. Each homework will be graded out of 100 possible points. In any problem asking you to design an algorithm please also provide proper pseudocode (mathematical notation), complexity analysis (both space and time), and brief justification of complexity and correctness.

All assignments must be turned in with a signed coverpage. If no coverpage is provided, the assignment will not be graded.

If there are any discrepancies in grades please see Jory Denny during his office hours (not the TA or Grader).