Question: Write a program that calculates the union and intersection of two sets of numbers. The sets can be represented using arrays. The general idea is

Write a program that calculates the union and intersection of two sets of numbers. The sets can be represented using arrays. The general idea is that a[i] != 0 if i is in the set and a[i] == 0 if it is not. Array element a[i] can thus be treated as a boolean, and the array a as a boolean vector. Since the array has a fixed bound, say N, the values in the set are restricted to the range 0..N. For example, the array a[6]={0,0,1,0,1,1} would represent the set {2,4,5}, because a[2], a[4] and a[5] have value 1 and everywhere else a contains zeros. Your program should contain the following functions: //computes union void compute_union(int max_size, int set1[], int set2[], int set_union[]); //computes intersection void compute_intersection(int max_size, int set1[], int set2[], int set_intersection[]); //tests for membership of element in set int in(int max_size, int set[], int element); The functions compute_union and compute_intersection should use function in in their implementation. The main function should read two sets of numbers A and B, call the functions compute_union and compute_intersection and display the results. Make N equal to 10.

Example:

Enter number of elements in set A: 5

Enter set A: 0 4 2 1 6

Enter number of elements in set B: 3

Enter set B: 1 9 3

Union: 0 1 2 3 4 6 9

Intersection: 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!