Homework Assignment 4
Due: Feb. 9 before class starts
Assignment
- (10 points) At what positions of a heap might the largest key be stored? Assume all of the heap keys are unique. Provide a statement and proof. Hint: use contradiction.
- (10 points) Bill claims that a preorder traversal of a heap will list its keys in nondecreasing order. Provide a counter proof (a counter proof means a contradicting example) of this claim. Use an image to aid your proof.
-
(40 points) Tamarindo Airlines wants to give a first-class upgrade coupon to
their top
log n
frequent fliers, based on the number of miles accumulated, wheren
is the total number of the airline's frequent flyers. The algorithm they currently use, which runs inO(n log n)
time, sorts the flyers by the number of miles flown and then scans the sorted list to pick the toplog n
flyers. Describe and analyze an algorithm that identifies the toplog n
flyers inO(n)
time. Hint: solve the next problem first.- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
-
(40 points) Explain how the
k
largest elements from an unordered collection of sizen
can be found in timeO(n + k log n)
using a maximum-oriented heap.- Provide and explain pseudocode
- Statement and proof of time complexity
- Statement and proof of memory complexity
- Bonus. (10 points) A group of children want to play a game, called Unmonopoly, where in each turn two things happen. (1) A player takes a turn that changes their amount of money, (2) the player with the most money must give half of their money to the player with the least amount of money. What data structure(s) should be used to play this game efficiently? Justify your choice through some basic analysis.
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).