Question

In: Computer Science

Given two unsorted arrays of integers. a) Write a pseudocode algorithm which will output only the...

Given two unsorted arrays of integers.
a) Write a pseudocode algorithm which will output only the integers not common to both arrays. When writing pseudocode, consider that no implementation for data structures or algorithms exist.
b) Implement your algorithm in Modern C++

Solutions

Expert Solution

please upvote ,comment for any query . Thanks.

Note : pseudocode written fro C++ and also program compiled and tested for C++ in CodeBlock IDE. check attached image for output .

program just wrote for your reference please consider only pseudocode.

Pseudocode :


function main(){
  
   set i,j,matchFlag to zero
   while i less than length of array1
  
       for from m=0 to length of array1
      
           if element of array1 index i equals to element of array2 index m
               set matchFlag zero
               break
           else
               matchFlag to one
           endif
              
       endfor
       if matchFlag equals to one
           print "uncommon elements is " i index element of array1
           set matchFlag to zero
       endif
      
       for from x=0 to length of array2
      
           if element of array2 index j equals to element of array1 index x
               set matchFlag zero
               break
           else
               matchFlag to one
           endif
              
       endfor
      
       if matchFlag equals to one
           print "uncommon elements is " j index element of array2
           set matchFlag to zero
      
   endWhile

}end

Program in C++ :

#include<iostream>
using namespace std;
int main()
{
int array1[10]={2,49,7,39,304,403,10,9,5,9}; //unsorted array 1
int array2[10]={2,49,12,39,304,403,10,9,5,11}; //unsorted array 2
int matchFlag=0;
int matchFlag2=0;
int i=0,j=0;
while(i<10) //while loop from 0 to length of array
{
for(int x=0;x<10;x++) //for array1 match to array 2
{
if(array1[i]==array2[x])
{
matchFlag=0;
break;
}
else
{
matchFlag=1;
}

}

if(matchFlag==1)
{
cout<<"Number is "<<array1[i]<<endl; //print uncommon from array1
matchFlag=0;
}
for(int m=0;m<10;m++) //for array2 match with array 1
{
if(array2[j]==array1[m])
{
matchFlag=0;
break;
}
else
{
matchFlag=1;
}
}
if(matchFlag==1)
{
cout<<"Number is "<<array2[j]<<endl; //print uncommon from array2
matchFlag=0;
}
i++;
j++;
}

}

Output :


Related Solutions

Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions:...
Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions: • myAdd ( ): add an integer d to the array; return 0 if the operation is successful; return a negative number otherwise. • search ( ): given an integer d, if d is found in the array, return the index of the cell containing d. Return a negative number otherwise (e.g., d is not found in the array). • myRemove ( ): Step...
Write the algorithm, following the ideas given in class, for merging two sorted arrays into one...
Write the algorithm, following the ideas given in class, for merging two sorted arrays into one sorted array. Note the algorithm is not the one for merge sort. 2) What is the best asymptotic upper bound for the algorithm? List reasoning steps.
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need...
1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any...
1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n. For example given 3 the algorithm will print 14 (because 1 + 4 + 9 =14) You can use multiplication denoted as * in your solution and you do not have to define it (For example. 3*3=9) For example if n is 6 it will print: The sum...
6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic...
6-Write a module in pseudocode called magicSix(), which accepts two integers and displays a message “Magic 6!” if either of the two integers is a 6 or if their sum or difference is a 6. Otherwise, the program will display “Not a magic 6.” Note, you will need to determine the larger number when calculating the difference, to get a positive difference. You cannot use any built-in Python functions to do this. Type your pseudocode into your answer document. 7-...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax. (no [ ]'s or (ptr+1) stuff. input will be the number of input values to enter followed by the sum to compare with. print out the continuous sub-array of values that are equal to sum or the message 'no sum ofund.' there may be more than one sub-array to be found in...
Given an unsorted integer array A of size n, develop an pseudocode with time complexity as...
Given an unsorted integer array A of size n, develop an pseudocode with time complexity as low as possible to find two indexes i and j such that A[i] + A[j] = 100. Indexes i and j may or may not be the same value.
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2...
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2 of the same length n. What is the complexity of your algorithm?
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2...
Write pseudocode for an algorithm that calculates the Hamming distance between two strings s1 and s2 of the same length n. What is the complexity of your algorithm?
Write a program that uses two identical arrays of at least 25 integers. It should call...
Write a program that uses two identical arrays of at least 25 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in descending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT