Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have n amount of apples and n amount of bananas which will be paired up in n lunchboxes. Each lunchbox will contain one apple

I have n amount of apples and n amount of bananas which will be paired up in n lunchboxes. Each lunchbox will contain one apple and one banana to feed my n children and I want them to eat the same amount of food

The total value of a lunchbox = the value of the apple + the value of the banana.

However, the apples and bananas has different sizes, making them have different values. I want all of my lunchboxes to have as similar value as possible, or you could say that i want the weights of all of the lunchboxes to be as even as possible. I dont want one lunchbox to contain the smallest banana and the smallest apple, I want the boxes to have the same amount.

To solve this, I firstly want to find a way to pair upp the apples and bananas so that they are paired up optimally (meaning they have as similar values in the boxes as possible. Example: In an ideal world, I would be able to pair them up perfectly say n=4 apples=(4,3,2,1) bananas=(4,3,2,1) giving all lunchboxes the same value (5,5,5,5), the minimum difference between the highest value lunchbox and the lowest would be 0, however, since the apples and bananas have different values, I want it to come as close to even as possible, we might get apples=(10,15,16,11) bananas=(4,8,10,11) and i want to pair them upp evenly.

I want to find how to pair them up so they become as even as possible, however there will often be some lunchbox containing a bit higher value than the other so i also want the difference between the most valuable lunchbox, and the least valuable lunchbox to be as small as possible, assuming they are paired up optimally, meaning they are being as evenly distributed as possible first.

I want to design an algorithm (pseudocode preferably pyhton) that finds the smallest possible difference between the most and the least valuable lunchbox, after the apples and bananas are paired up optimally(=having as even weight/value as possible).

The time complexity must run faster or equal to O(n1.8) and not slower, with a unit cost analysis, assuming that adding or comparing two values takes O(1) time.

The input to the algorithm is the values: a1.....an for the n apples and b1......bn for the n bananas.

The algorithm only has to find the value, and not report which apple to combine with which banana.

example: if n=4 apples a=(9,14,15,10) bananas=(19,22,19,21) output would be 1

Please name what algorithms are being used and the method, (knapsack, greedy approach, divide and conquer etc.) Please argue for the correctness of the algorithm and give an analysis of the time complexity

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899