Question
I have n amount of stones and n amount of pearls, these will be paired up in n boxes, each box has one stone and
I have n amount of stones and n amount of pearls, these will be paired up in n boxes, each box has one stone and one pearl.
example: stones [3,20,10,3] pearls:[7,3,8,12]
The stones and pearls have different sizes -> making them different values. I want the value in the boxes to be as even as possible, so that each box contains similar value in comparison to the other boxes
I want to pair up the stones and pearls in a way so that the difference in value between the most valuable and the least valuable box is as small as possible. The total value of a box is the value of the stone + value of the pearl.
I want to design an algorithm (preferrably in python and pseudocode) that finds the smallest possible difference between the most and the least valuable box.
Where the input is stones: [s1....sn] for n stones
pearls: [p1.......pn] for n pearls
I only want to find the value, and not show which pearl to combine with which stone.
I want the time complexity to be fast, say O(n^1.5) or faster, not O(n^2), with assumption that adding/comparing two values takes O(1) time
I also would like to know the correctness of the algorithm and an analysis of its time complexity
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