Homework Assignment 3
Assignment
-
(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 listL
is cut into two listsL1
andL2
, whereL1
is the first half of L andL2
is the second half ofL
, and then these two lists are merged into one by taking the first element inL1
, then the first element inL2
, followed by the second element inL1
, the second element inL2
, and so on.- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
-
(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
andB
is the list of all ordered triples(x, y, z)
such that the pair(x, y)
is inA
and the pair(y, z)
is inB
. Describe and analyze an efficient algorithm for computing the natural join of a listA
ofn
pairs and a listB
ofm
pairs.- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
-
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 cellA[i]
, we can store a pair(i, e)
inL
, wheree
is the element stored atA[i]
. This approach allows us to representA
usingO(m)
storage, wherem
is the number of nonnull entries inA
. Describe and analyze efficient ways of performing the methods of the array list ADT on such a representation.- Provide and explain pseudocode for all ADT methods
- 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
- 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 (click here for pdf) worked out to see the expected format and
the tex file (click here to see it) that
generated it to help you start.
- If you are unfamiliar with LaTex, here is a short tutorial (click here for pdf) and the tex file (click here to see it) 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.
- Complete every part of every problem!
- On writing an algorithm, use pseudocode and good mathematical style to describe algorithms and data structures. Do not specify Java code unless otherwise stated.
- On time complexity, your goal should be to determine and prove the tightest bound for your algorithm. Be sure to state any assumptions about implementations needed.
- On memory complexity, your goal is to analyze the extra memory consumed by your algorithm, i.e., do not count the memory used by the input to your algorithm.
- 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 one minute after class starts. Details:
- The first page of your hard copy must be a signed coverpage (click here for pdf).
- 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, consult University of Richmond webpages to learn how to use campus printers. If possible, please print 2-sided. Printer issues are not an excuse to turn an assignment in late.
- Staple all pages together.
- 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.
Grading
- Each assignment is graded out of 100 points (not including bonus).
- Expectation and point distribution - this is a general guideline that may
change depending on the specific problem, e.g., proof-only problems may
differ.
- Algorithm description and pseudocode - ~50%
- Provide a written explanation of your algorithmic solution. Provide intuition as to why it computes the correct answer.
- Provide pseudocode of your solution. Be sure to clearly state input and output (if applicable, and a return statement must also be present), and be sure to use ADTs as specified in slides and textbook.
- Statement and proof of time complexity - ~25%
- Provide a theorem/lemma stating assumptions and results.
- Provide a clear proof sketch justifying theorem.
- Statement and proof of memory complexity - ~25%
- Provide a theorem/lemma stating assumptions and results.
- Provide a clear proof sketch justifying theorem.
- Algorithm description and pseudocode - ~50%
- Criteria (includes but is not limited to)
- Efficiency solutions - inefficient algorithms will yield partial credit to the problem.
- Clear and concise technical writing and presentation is the heart of the grade. It is not merely that you solve the problem, it is a function of how well you write your pseudocode and theorems, and how they are explained and proved. Short statements of fact and clear equations are valued over unclear, complex, and lengthy expositions.
- Proper use of LaTeX is also expected. Points will be deducted for not using mathematics mode or LaTeX tables for example.
- If there are any discrepancies in grades, please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).