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
What is the difference between typedef struct and struct?
What are the key features in c programming language?
If you know then define #pragma?
Mention four important string handling functions in c languages .
What is a node in c?
How pointers are declared?
What is the use of putchar function?
Is using exit() the same as using return?
Define macros.
How can I recover the file name given an open stream or file descriptor?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
What will the preprocessor do for a program?
What is the use of header?
What is union and structure in c?
what is recursion in C