Section 1.1 5. Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the
Posted: Tue Jul 12, 2022 8:10 am
Section 1.1 5. Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists 2, 5, 5, 5 and 2, 2, 3, 5, 5, 7, the output should be 2, 5, 5. What is the maximum number of comparisons your algorithm makes if the lengths of the two given lists are m and n, respectively? Section 1.2 9. Consider the following algorithm for finding the distance between the two closest elements in an array of numbers. Algorithm MinDistance (A[0..n-1]) //Input: Array A[0..n-1] of numbers //Output: Minimum distance between two of its elements dmin - x for i 0 to n - 1 do for j 0 to n - 1 do if i ‡ j and |A – A[j]| <dmin dmin A A[j]| return dmin Make as many improvements as you can in this algorithmic solution to the problem. If you need to, you may change the algorithm altogether; if not, improve the implementation given.