Homework Assignment 7
Due: Mar. 28 before class starts
Assignment
-
(30 points) Suppose we are given two
n
-element sorted sequencesA
andB
each with distinct elements, but potentially some elements that are in both sequences. Describe anO(n)
-time method for computing a sequence representing the unionA ∪ B
(with no duplicates) as a sorted sequence.- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
-
(30 points) Describe a radix-sort method for lexicographically sorting a
sequence
S
of triplets(k, l, m)
, wherek
,l
, andm
are integers in the range[0, N - 1]
, for someN ≥ 2
. How could this scheme be extended to sequences ofd
-tuples(k1, k2, ..., kd)
, where eachki
is an integer in the range[0, N - 1]
?- Provide and explain pseudocodes
- Statement and proof of time complexities
- Statement and proof of memory complexities
-
(40 points) Linda claims to have an algorithm that takes an input sequence
S
and produces an output sequenceT
that is a sorting of then
elements inS
.- Give an algorithm,
isSorted
, for testing inO(n)
time ifT
is sorted.- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
- Explain why the algorithm
isSorted
is not sufficient to prove a particular outputT
of Linda's algorithm is a sorting ofS
. - Describe what additional information Linda's algorithm could output so
that her algorithm's correctness could be established on any given
S
andT
inO(n)
time.
- Give an algorithm,
-
Bonus.
(10 points) Space aliens have given us a program,
alienSplit
, that can take a sequenceS
ofn
integers and partitionS
inO(n)
time into sequencesS1, S2, ..., Sk
of size at most⌈n/k⌉
each, such that the elements inSi
are less than or equal to every element inSi+1
, fori = 1, 2, ..., k - 1
, for a fixed number,k < n
. Show how to usealienSplit
to sortS
inO(n log n / log k)
time.- Provide and explain pseudocode
- Statement and proof of time complexity
General Instructions, Turning in assignments, and Grading
General Instructions
- All homework assignments must be typeset using LaTex. Using another program (e.g., Microsoft Word) or handwriting assignments will result in grade of 0. Here is an example homework problem worked out to see the expected format and the tex file that generated it to help you start.
- If you are unfamiliar with LaTex, here is a short tutorial and the tex file that generated it. This tutorial shows how to write common mathematics, how to write pseudocode, how to cite sources, how to include images, and how to include tables.
- Use pseudocode and good mathematical style to describe algorithms and data structures. Do not specify Java code unless otherwise stated. Described more in example homework document above.
- Complete every part of every problem!
- Follow turn-in instructions precisely.
- Failure to complete any of these steps will result in a significant loss of points.
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:
- The first page of your hard copy must be a signed coverpage.
- Next put the problems in order as described in the description. This may seem silly but you would be surprised sometimes.
- If you do not know how to print you may have to consult University of Richmond webpages to learn how to use campus printers. If possible, please print 2-sided.
- Staple all pages together.
- Turn in packet before class begins.
- I reserve the right to assign a 0 to any assignment failing to comply with these instructions. Even for something as small as a missing staple.
Points
- Each assignment is graded out of 100 points (not including bonus).
- Criteria and point distribution (This distribution is a general guideline
that may change depending on the specific problem - exceptions for example
include but are not limited to proof-only problems.)
- Approximately 50% on a problem is devoted to the algorithm. This includes items like describing a correct and efficient algorithm, using proper and clear pseudocode, and describing your algorithm clearly.
- Approximately 25% on a problem is devoted to time complexity. This includes stating a lemma or theorem of your result and providing a proof and justification of the result.
- Approximately 25% on a problem is devoted to memory complexity. This includes stating a lemma or theorem of your result and providing a proof and justification of the result.
- If the problem is simply a proof, 100% is split between a proper statement (lemma or theorem) of the result and proving a clear and concise proof of the result.
- You can receive points off for not following formatting guidelines.
- If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).