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
Can you please explain the scope of static variables?
What is the difference between malloc() and calloc()?
What is restrict keyword in c?
what do you mean by enumeration constant?
Explain what is wrong with this statement? Myname = ?robin?;
What is property type c?
What does %2f mean in c?
What is the function of multilevel pointer in c?
What does c mean in basketball?
How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?
How is a structure member accessed?
Can we use visual studio for c?
What is the use of sizeof?
Should I learn c before c++?
What is #include stdio h?