The elements of the two arrays are taken as input**. The union and intersection are performed on the two given arrays**. The union of two arrays will contain all the elements of the two arrays, the common elements will appear only once instead of twice. The intersection of the two arrays will contain the common elements of the two arrays.

```
INPUT: two Array elements
OUTPUT: the union and intersection of two arrays
PROCESS:
Step 1: [taking the input]
Read m [number of elements of the first array]
For i=0 to m-1 repeat
Read a[i]
[end of ‘for’ loop]
Read n [number of elements of the second array]
For i=0 to n-1 repeat
Read b[i]
[End of ‘for’ loop]
Step 2: [union and intersection of two arrays]
For i=0 to m-1 repeat
Set u[i]<-a[i]
[End of ‘for’ loop]
Set j<-i
For i=0 to n-1 repeat
Set c<-0
For k=0 to j-2 repeat
If b[i]=u[k] then
Set c<-c+1
[End of ‘if’]
[End of ‘for’ loop]
If c=0 then
Set u[j]<-b[i]
Set j<-j+1
[End of ‘if’]
[End of ‘for’ loop]
[displaying the union of the array]
Print "The union of two arrays is: "
For i=0 to j-1 repeat
Print u[i]
[End of ‘for’ loop]
[performing intersection of two arrays]
Set k<-0
For i=0 to m-1 repeat
Set c<-0
For j=0 to n-1 repeat
If a[i]=b[j] then
Set c<-c+1
[End of ‘if’]
[End of ‘for’ loop]
If c≠0 then
Set in[k]<-a[i]
Set k<-k+1
[End of ‘if’]
[End of ‘for’ loop]
[displaying the intersection of the array]
Print "The intersection of two arrays is: "
For i=0 to j-1 repeat
Print in[i]
[End of ‘for’ loop]
Step 3: Stop.
```

Related

- Find Maximum and Minimum from an array
- Kth Largest and Smallest Element
- 2nd largest element from the array
- Find how many negative numbers are present in the array
- The elements of the one array are copied to another array.
- Delete element from any position in array
- Frequency of each element in the Array
- Find out the unique elements from the Array
- Finds odd and even elements from the array and stored in two separate arrays
- Counts the number of odd and even elements separately from the array
- Reverses the elements of an Array
- Merge two Array and stored in the third Array
- Rotated the Array at left
- Rotated the Array right
- Sort number of strings in an array
- Check one given element of an array present more than n/2 times or not.
- Sum of the elements of an Array is calculated using a pointer