Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote