if array a conatins 'n' elements and array b conatins 'n-1'
elements.array b has all element which are present in array
a but one element is missing in array b. find that
element.
Answer Posted / argho chatterjee
// Assuming arrays are sorted in ascending order
/*
it is not efficient if the number is found at the start of
the array.
It tries to break the array and find the position from the
middle and then again breaks till it find the position of
the array.
*/
public static void main(Array mainArray , Array
missingArray) {
int pointer = mainArray.length /2; // default is 0
return findMissingElement
(mainArray ,missingArray,pointer);
}
int findMissingElement(Array mainArray , Array
missingArray,pointer) {
if(mainArray[pointer] ==
missingArray[pointer] ) {
pointer = pointer + pointer /2;
return
findMissingElement
(mainArray ,missingArray,pointer);
}
else {
return mainArray[mainArray.length/i];
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How is a structure member accessed?
Compare array data type to pointer data type
How do you print an address?
Can the “if” function be used in comparing strings?
What are shell structures used for?
What is a union?
What does the && operator do in a program code?
Write a program for Overriding.
How to delete a node from linked list w/o using collectons?
What is c language & why it is used?
How do you redirect a standard stream?
What does do in c?
printf(), scanf() these are a) library functions b) userdefined functions c) system functions d) they are not functions
why return type of main is not necessary in linux
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above