Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Suppose you are given two arrays A[1..n], B[1..n] of elements. You are required to find the pair of elements A[i], B[j] such that their
Suppose you are given two arrays A[1..n], B[1..n] of elements. You are required to find the pair of elements A[i], B[j] such that their absolute difference is the smallest over all such pairs. 1. (2 points) Describe briefly the brute force algorithm and state and justify informally its running time. 2. (8 points) A better solution is to use a variant of the Merge algorithm from MergeSort. This solution is given on many web sites, but try to not look at those solutions. Sort the arrays in increasing order. Compare the two first elements and note the difference. Then, decide which list to "remove" the minimum element from. Try some examples and come up with a strategy that you think works. The algorithm should be to keep applying this strategy and always compare the absolute difference between the two minimum values in A, B to a running minim difference and updating the minimum difference if necessary until all elements in A and B have been "removed". Write the above algorithm in pseudocode and prove its correctness. Also state and justify informally the running time of this algorithm. Activate Windo Go to Settings to ad
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