Design an algorithm to find all the common elements in two sorted lists of numbe
ID: 2247412 • Letter: D
Question
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? a. Find god (31415.14142) by applying Euclid's algorithm. b Estimate how many times faster it will be to find gcd(314l5.14142) by Euclid's algorithm compared with the algorithm based on checking con secretive integers from min(m n) down to god (m, n). Prove the equality god (m n) = god (n m mod n) for every pair of positive integers m and n.Explanation / Answer
Answer:-
In this problem take both list inan array let say a[] and b[] and size is m and n respectively.
i=0 and j=0 c=0(counter c store no of common element in both list)
while(i<m&&j<n)
if(a[i]==b[j])
{
i++ and j++
c++
}
else if(a[i]>a[j]){
j++;
}
else
i++;
end of while
print c;
kindlly rate my answer if you like then please thumbs up.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.