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
When should the volatile modifier be used?
Process by which one bit pattern in to another by bit wise operation is?
how to write optimum code to divide a 50 digit number with a 25 digit number??
When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd
What is the difference between arrays and pointers?
What's a good way to check for "close enough" floating-point equality?
What is null character in c?
What is spaghetti programming?
What is the use of bit field?
What does the c in ctime mean?
How can I call a function with an argument list built up at run time?
how do you programme Carrier Sense Multiple Access
Why main is not a keyword in c?
In C programming, what command or code can be used to determine if a number of odd or even?
Are pointers integers in c?