Design an algorithm that, given two lists of integers, creates a list consisting
ID: 3758227 • Letter: D
Question
Design an algorithm that, given two lists of integers, creates a list consisting of those integers that appear in both lists (each integer on the final list should appear only once). Describe your algorithm in terms of a pseudocode focusing on main algorithmic tasks and not on low-level details. Analyze the running time of your algorithm. You will get full credit only if your algorithm achieves an asymptotically better worst-case performance than (n 2 ), where n is the sum of the lengths of the two input lists.
Explanation / Answer
1. Traverse list1 and add the distinct elements of list in a dictionary, where key
will be the element and value will be number of times it occur
2. Traverse list2 and add all elements to dict, if it exists update the count
3. Traverse dictionary and print values where count is equal to 2.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.