Answered step by step
Verified Expert Solution
Question
1 Approved Answer
7. Jack Ostrich, a notorious pirate, has come across a single-file convoy of merchant ships that he would like to plunder. Some of these ships,
7. Jack Ostrich, a notorious pirate, has come across a single-file convoy of merchant ships that he would like to plunder. Some of these ships, however, are well defended, and the cost of repairing Jack's ship, the Blue Pearl, after engaging them would amount to more than their treasure is worth. Further complicating measures is the fact that, while Jack can choose any point in the convoy to break off, he cannot return after doing so, and must engage each ship in the convoy up to that point. For example, consider the following convoy: 5 6-9 2-8 4 -7 3 -5 Then, breaking off the convoy after the second ship would be the best option, as it yields a net profit of 11 (which is the highest possible given this convoy). Assuming that Jack has already calculated the cost or benefit to plundering each merchant ship: (a) Give an O(n) algorithm that will let him walk away with the maximum net profit. (b) Suppose Jack has hired an expert navigator, and can now choose an interception point as well as a breakoff point. Give an O(n * log(n)) algorithm that makes the best use of his new ability
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started