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 extern c used for?
Explain bitwise shift operators?
Define circular linked list.
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
How many levels deep can include files be nested?
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
What are the advantages and disadvantages of a heap?
What does void main () mean?
Explain About fork()?
What are the data types present in c?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
Can you define which header file to include at compile time?
Why is sizeof () an operator and not a function?
What is the difference between fread and fwrite function?
Why isn't any of this standardized in c? Any real program has to do some of these things.