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...
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 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 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...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays of integers. Neither list contains duplicates, and the resulting list should not contain duplicates either. Hint: You may want to call a helper function from merge. PROGRAM: C
Evaluate and write an algorithm to find the largest item in an unsorted singly linked list...
Evaluate and write an algorithm to find the largest item in an unsorted singly linked list with cells containing integers
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT