Homework Assignment 3


Assignment

  1. (50 points) Describe a method for performing a card shuffle of a list 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.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  2. (50 points) A useful operation in databases is the natural join. If we view a database as a list of ordered pairs of objects, then the natural join of databases A and B is the list of all ordered triples (x, y, z) such that the pair (x, y) is in A and the pair (y, z) is in B. Describe and analyze an efficient algorithm for computing the natural join of a list A of n pairs and a list B of m pairs.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  3. Bonus. (10 points) 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 a pair (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 methods of the array list ADT on such a representation.
    1. Provide and explain pseudocode for all ADT methods
    2. Statement and proof of time complexity for all ADT methods. Be clear of the assumptions on the ADT implementations.


General Instructions, Turning in assignments, and Grading

General Instructions

Turn in Instructions

Each assignment will be turned in in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean one minute after class starts. Details:

Grading