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

write an algorithm NOT a code Intersection of two number sets – the intersection

ID: 3764032 • Letter: W

Question

write an algorithm NOT a code

Intersection of two number sets – the intersection of two number sets is defined as the numbers found in both sets. For example if the first set contained the numbers {5 10 8 25 9 15 22} and the second set contained the numbers {20 22 10 9}, the intersection would be {10 and 9}. Write an algorithm (don’t worry about writing the code) that would determine the intersection of two sets of numbers. You should count the number of values in common as well determine which numbers are in common.

Explanation / Answer

Intersection(A, B) /*Where A and B are 2 sets.*/

Take an empty set C.

1. For each element in the set A (assume it is copied to x):

1.1. For each element in set B (assume it is copied to y):

1.1.1. If x == y

1.1.1.1. Add x to the set C.

Return the set C.

If you need any further clarification, just get back to me.