Homework 7


Due Date: Oct. 30th (before class)


Assignment

  1. R11.8 (Pg. 545)

    Suppose we are given two n-element sorted sequences A and B that should not be viewed as sets (that is, A and B may contain duplicate entries). Describe an O(n)-time method for computing a sequence representing the set AB (with no duplicates). Provide pseudocode for the algorithm, an informal argument as to its correctness, complexity and its justification.

  2. R11.20 (Pg. 546)

    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. Provide pseudocode for the algorithm and its correctness. 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]? State what and where in your pseudocode you will be making the necessary changes for the generalized algorithm with d tuples. Justify its correctness and state its complexity with justification.

  3. R11.26 (Pg. 547)

    Show that the worst-case running time of quick-select on an n-element sequence is Ω(n2).

  4. C11.2 (Pg. 547)

    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. Justify the correctness and complexity of your algorithm.
    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.


Bonus

    C11.29 (Pg. 549)

    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(nlog n/log k) time.