Homework Assignment 4


Due: Feb. 9 before class starts


Assignment

  1. (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.
  2. (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.
  3. (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, where n is the total number of the airline's frequent flyers. The algorithm they currently use, which runs in O(n log n) time, sorts the flyers by the number of miles flown and then scans the sorted list to pick the top log n flyers. Describe and analyze an algorithm that identifies the top log n flyers in O(n) time. Hint: solve the next problem first.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  4. (40 points) Explain how the k largest elements from an unordered collection of size n can be found in time O(n + k log n) using a maximum-oriented heap.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity
    3. Statement and proof of memory complexity
  5. 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

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:

Points