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 A ∪ B (with no duplicates). Provide pseudocode for the algorithm, an informal argument as to its correctness, complexity and its justification.
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.
Show that the worst-case running time of quick-select on an n-element sequence is Ω(n2).
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.
isSorted
, for testing in O(n) time if T is sorted. Justify the correctness and complexity of your algorithm. isSorted
is not sufficient to prove a particular output T of Linda's algorithm is a sorting of S.
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.