AIM : To define and accept 2 arrays and perform set operations like union, intersection,
difference and symmetric difference using loops, conditional statements and array
indexes.
OBJECTIVE : Learn the handling of arrays using ‘C’ statements. Study single
dimensional array, see how to represent sets using single dimensional array and learn to
use loops and array indexes
THEORY:
1) Sets, set operations-Union, intersection, difference, symmetric difference of sets
2) 1 Dimentional array and its use to represent sets and its operations
Sets: A set is a collection of distinct objects, where the object may be atomic(single
item) or a set.
Operations on sets:
Union of sets S1 and S2 is :
S1={1,5,3,2,4}
S2={3,1,4,5,6}
S1 U S2 = {1,5,3,2,4,6}
int array2[]={10,29,36,44,51}
Integer array of 5 elements stored in array2[0],array2[1],array2[2], array2[3]and
array2[4]
float array3[10];
Float array of reserved size 10
char array4[]=”example string”;
Character array initialized to “example string”
2. Algorithm INTERSECTION
1) Accept 2 integer arrays array1 and array2 of size say m, n respectively.
2) Initialize a third array array3 of at least the size m+n.
3) Compare first element of array1 with all elements of array2. If common then add to
array3.
5) Repeat step 4 for all array elements of array1.
6) Print array3.
3. Algorithm DIFFERENCE
1) Accept 2 integer arrays array1 and array2 of size say m, n respectively.
2) Initialize a third array array3 of at least the size m.
3) Compare first element of array1 with all elements of array2. If unique then add to
array3.
5) Repeat step 4 for all array elements of array1.
6) Print array3.
4. Algorithm SYMMETRIC_DIFFERENCE
1) Accept 2 integer arrays array1 and array2 of size say m, n respectively.
2) Initialize a third array array3 of at least the size m, array4 of size n and array5 of
size m+n.
3) Compare first element of array1 with all elements of array2. If unique then add to
array3.
4) Repeat step 3 for all array elements of array1.
5) Compare first element of array2 with all elements of array1. If unique then add to
array4.
6) Repeat step 6 for all array elements of array2.
7) Make union of array3 and array4 into array5.
8) Print array5
(Note: array3 and array 4 have unique elements so instead of making array4, the
elements can be added in the end of array3 itself and array3 printed in the end. Also,
the symmetric difference can be achieved by (A U B)-(A ∩B) )
INSTRUCTIONS:-