Homework Assignment 7


Due: Mar. 28 before class starts


Assignment

  1. (30 points) Suppose we are given two n-element sorted sequences A and B each with distinct elements, but potentially some elements that are in both sequences. Describe an O(n)-time method for computing a sequence representing the union A ∪ B (with no duplicates) as a sorted sequence.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  2. (30 points) Describe a radix-sort method for lexicographically sorting a sequence S of triplets (k, l, m), where k, l, and m are integers in the range [0, N - 1], for some N ≥ 2. How could this scheme be extended to sequences of d-tuples (k1, k2, ..., kd), where each ki is an integer in the range [0, N - 1]?
    1. Provide and explain pseudocodes
    2. Statement and proof of time complexities
    3. Statement and proof of memory complexities
  3. (40 points) Linda claims to have an algorithm that takes an input sequence S and produces an output sequence T that is a sorting of the n elements in S.
    1. Give an algorithm, isSorted, for testing in O(n) time if T is sorted.
      1. Provide and explain pseudocode
      2. Statement and proof of time complexity
      3. Statement and proof of memory complexity
    2. Explain why the algorithm isSorted is not sufficient to prove a particular output T of Linda's algorithm is a sorting of S.
    3. Describe what additional information Linda's algorithm could output so that her algorithm's correctness could be established on any given S and T in O(n) time.
  4. Bonus. (10 points) Space aliens have given us a program, alienSplit, that can take a sequence S of n integers and partition S in O(n) time into sequences S1, S2, ..., Sk of size at most ⌈n/k⌉ each, such that the elements in Si are less than or equal to every element in Si+1, for i = 1, 2, ..., k - 1, for a fixed number, k < n. Show how to use alienSplit to sort S in O(n log n / log k) time.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity


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 five minutes after class starts. Details:

Points