Question: /** * func: join_plus_max * preconditions: both the calling object and the parameter are sorted-pareto lists (if not, nullptr is returned). * desc: imagine a

/** * func: join_plus_max * preconditions: both the calling object and the parameter are sorted-pareto lists (if not, nullptr is returned). * desc: imagine a different scenario (vs. join_plus_plus): you are a parent with two children -- one living in city A and * the other living in city C -- and they are both coming home for the holidays (let's call your home C). * You have a pareto-sorted option list for the A-to-C trip (this is the calling object) and a pareto-sorted option list * for the B-to-C trip. * Consider a particular option for the A-to-C trip  and a particular option for the B-to-C trip . * Clearly, the total price for selecting these two options is p1+p2. * However (unlike in the plus_plus case), adding the t1 and t2 doesn't make sense right (the trips are in "parallel"). * What you care about as a parent is when BOTH of your children are home. This is determine by MAX(t1,t2). * Thus, the resulting "composite" option in this case would be  (hence the name join_plus_max). * * Your job is to construct the sorted-pareto "composite" option list capturing the options for getting both children home. * The resulting TravelOptions object is returned as a pointer (recall if the preconditions are not met, * nullptr is returned). * * RUNTIME: let N and M be the lengths of the respective lists given; your runtime must be linear in N+M (O(N+M)). * * status: TODO * * TIPS: * This one will take some thought! If the specified runtime is possible, the resulting option list cannot be too * large right (at most N+M in length)? But there NxM possible pairing of options. So enummerating all pairs * of options cannot be an option (as was suggested for the _plus_plus case). * * Start by figuring out what the FIRST (cheapest) option in the resulting list MUST be. * Remember that a sorted-pareto list must be strictly increasing in price and strictly decreasing in time. * Now think about what might be the 2nd option in the list you are building. It must cost more than the first AND * take less time. To be more concrete, suppose your first option has total price of $100 and results in child A * traveling for 12 hours and child B traveling for 8 hours. Does it make sense to spend more money on child B * so they can get home in say 7 hours? Think about it! The MAX function is important! */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!