I need to compare between two int arrays of different size.
It has to be most efficient.
Is it possible to do in O(N * log(N)) time?
It should print integers that differ between the two arrays.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The algorithm is O(n), but you are assuming that the arrays are equally sized and each one has a size of
ARY_SIZE.I will not solve the entire homework for you, but I suggest you start with the following function header:
int compar2arr(int arrA[], int arrA_size, int arrB[], int arrB_size).Keep in mind that for function arguments
int arrA[]is merely equivalent toint* arrA.As noted by Keith and Sebastian,
arrA_size != arrB_sizeimplies different (unless an author of the task defines it in other way). So you check it at the begining and returnfalseif it holds.EDIT
Ok, I re-read your post and it seems you need to just display all the not-equal elements and you do not know how to deal with the fact they are of different sizes.
Therefore I suggest to start with the following:
I am sure you can come up with the actual code to replace comments.
It is not the most concise way to write, but wanted to keep it easy to understand. Anyway, the computational complexity is O(n), the best possible.