hw3

.pdf

School

Purdue University *

*We aren’t endorsed by this school

Course

381

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

5

Uploaded by BailiffKangaroo6144

Report
CS 381-Fall 2020 Homework 3 Due Date: Feb 29, 2024 at 11:59PM on Gradescope. Instructors: Jeremiah Blocki and Simina Branzi Name: Purdue ID: Learning Objectives The homework is relevant to the following learning objectives: LO 1.1 Students are able to provide examples of divide-and-conquer algorithms to solve fundamental problems (e.g., Sorting, Multiplication, Skyline, Finding the Mean) and identify the three main components of a divide-and-conquer algorithm (Divide, Conquer and Merge). Students should be able to design their own divide-and-conquer algorithms to solve problems. LO 1.2 Students are able to provide examples of greedy algorithms and design their own greedy algorithms to solve problems when applicable. Students should be able to provide counter-examples when a proposed greedy algorithm is incorrect. LO 3.1 Students are able to use induction/invariants to prove that a divide-and-conquer algorithm is correct. LO 3.2 Students are able to prove that a greedy algorithm is correct using exchange arguments, contradiction and structural arguments. Homework Guideline Reminders Assignments must be typed. Submit one pdf file to Gradescope by 11:59PM, or else late penalties will apply. The pdf file can include hand-drawn images of figures. Each question needs to start with the resources and collaborator (RC) statement. You will not be penalized for using resources or having collaborators if your answers are expressed in your own words. If you consulted no resources outside of course material or had no collaborators, you must state so. A question without a complete RC statement will not be graded. 1
Question 1 (25 points) (Double Inversions) Given an array A with n positive integers a 1 , . . . , a n 1 we say that a pair ( i, j ) forms a double inversion if i < j but a i > 2 a j . If j = i + 1 we call the pair ( i, j ) a consecutive double inversion. (a) (7 points) Alice claims that if the array contains a double inversion ( i, j ) then the array must contain a consecutive double inversion. Do you agree with Alice’s claim? If so prove that Alice’s claim is true. If not provide a counterexample. (b) (18 points) Give an efficient algorithm to count the number of double inversions. Prove that your algorithm is correct and analyze the running time of your algorithm. Collaborators: Resources: 2
Question 2 (25 points) There are n seals that live in igloos along Arctic Road which is 100 n meters long. As input we are given n positive integers 0 a 1 . . . a n 100 n indicating the location of seal i ’s igloo (You may assume that the list a 1 a 2 . . . a n is given in sorted order). The seals are worried about polar bear attacks. Fortunately, there is a new amazing device called the Polar Bear Repeller 9000 which has been scientifically proven to scare off polar bears. In particular, if the Polar Bear Repeller 9000 is installed at location x on Artic Road then one can be sure that there will be no Polar Bear attacks within a n meter radius i.e., any igloo a i [ x n, x + n ] is guaranteed to be a safe location. The seals want to guarantee that every seal igloo is safe from polar bear attacks. Unfortunately, the Polar Bear Repeller 9000 is expensive to purchase and maintain. Thus, the seals want to minimize the number of Polar Bear Repeller’s that they install in order to protect all of the igloos. (a) (5 points) How many Repeller’s are necessary in the worst case? Give an example of a worst case input a 1 . . . a n which maximizes the number of Polar Bear Repeller 9000’s nececessary to protect all of the seals. (b) (10 points) Gulliver seal proposes the following greedy algorithm: find a location x which covers the maximum number of previously uncovered seal houses and install a Repeller at location x . Repeat until all seal houses are covered. Does Gulliver’s algorithm minimize the total number of Polar Bear Repeller 9000’s that are installed? If not you should give a counter-example. If so you should prove that Gulliver’s algorithm works and analyze the running time. (c) (10 points) Oliver seal proposes the following greedy algorithm: find the minimum i such that igloo i is currently uncovered and install a Repeller at location a i + n . Repeat until all seal houses are covered. Does Oliver’s algorithm minimize the total number of Polar Bear Repeller 9000’s that are installed? If not you should give a counter-example. If so you should prove that Oliver’s algorithm works and analyze the running time. Collaborators: Resources: 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help