- Section 1 1 5 Design An Algorithm To Find All The Common Elements In Two Sorted Lists Of Numbers For Example For The 1 (272.58 KiB) Viewed 18 times
Section 1.1 5. Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Section 1.1 5. Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the
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.