Design a simple 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?
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
Let’s say |A|=m and |B|=n.
We use two variables i and j. The first iterates through the first sorted list and the second iterates through the second sorted list....
This is only a preview of the solution. Please use the purchase button to see the entire solution