3) Brute-Force Algorithm - Create the Difference of Two Sets
Given two arrays of Integers A and B with len(A) = n and len(B) = m, create a third array C that
includes all elements of A that are not in B. We write this operation as “A – B”; we call the
operation set difference; and we call the result the difference of the two sets A and B (or simply
“A minus B”). Assume that in each array, each element is listed only once (there are no
duplicates within the same array), but the elements are not sorted.
a) Write a brute force function that uses nested for loops to repeatedly check if each element in A
matches any of the elements in B. If the element from A does not match any element in B, then
copy it into the next available slot of array C. Do not sort any of the arrays at any time.
Example: With A = [2, 4, 6] and B = [3, 4, 5], your algorithm should produce C = [2, 6].
b) Trace the algorithm with
A = [20, 40, 70, 30, 10, 80, 50, 90, 60]
B = [35, 45, 55, 60, 50, 40]
c) Perform asymptotic analysis to determine the maximum number of comparisons of array
elements that are needed. What is the Big-Oh class for this algorithm in terms of m and n?